diff --git a/.vscode/launch.json b/.vscode/launch.json index abdc4a4..5f99504 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(lldb) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/bld/debug/lua_callback_eh", + "program": "${workspaceFolder}/bld/debug/capture_exception_async_test", "args": [ ], "cwd": "${workspaceFolder}", "stopAtEntry": false, diff --git a/doc/LEAF-2.png b/doc/LEAF-2.png index 1237ef2..56803bb 100644 Binary files a/doc/LEAF-2.png and b/doc/LEAF-2.png differ diff --git a/doc/leaf.adoc b/doc/leaf.adoc index 7e97d26..1a21583 100644 --- a/doc/leaf.adoc +++ b/doc/leaf.adoc @@ -629,21 +629,21 @@ enum class err2 { e1, e2 }; T f() { if( error_detected ) - throw leaf::exception(err1::e1, err2::e2); + leaf::throw_exception(err1::e1, err2::e2); // Produce and return a T. } ---- [.text-right] -<> +<> -The `leaf::exception` function handles the passed error objects just like `leaf::new_error` does, and then returns an object of a type that derives from `std::exception` (which the caller throws). Using this technique, the exception type is not important: `leaf::try_catch` catches all exceptions, then goes through the usual LEAF error handler selection procedure. +The `leaf::throw_exception` function handles the passed error objects just like `leaf::new_error` does, and then throws an object of a type that derives from `std::exception`. Using this technique, the exception type is not important: `leaf::try_catch` catches all exceptions, then goes through the usual LEAF error handler selection procedure. -If instead we want to use the legacy convention of throwing different types to indicate different failures, we simply pass an exception object (that is, an object of a type that derives from `std::exception`) as the first argument to `leaf::exception`: +If instead we want to use the legacy convention of throwing different types to indicate different failures, we simply pass an exception object (that is, an object of a type that derives from `std::exception`) as the first argument to `leaf::throw_exception`: [source,c++] ---- -throw leaf::exception(std::runtime_error("Error!"), err1::e1, err2::e2); +leaf::throw_exception(std::runtime_error("Error!"), err1::e1, err2::e2); ---- In this case the returned object will be of type that derives from `std::runtime_error`, rather than from `std::exception`. @@ -828,7 +828,7 @@ The following figure illustrates the slightly different error communication mode .LEAF Error Communication Model Using Exception Handling image::LEAF-2.png[] -The main difference is that the call to `new_error` is implicit in the call to the function template `leaf::exception`, which in this case takes an exception object of type `Ex`, and returns an exception object of unspecified type that derives publicly from `Ex`. +The main difference is that the call to `new_error` is implicit in the call to the function template `leaf::throw_exception`, which in this case takes an exception object of type `Ex`, and throws an exception object of unspecified type that derives publicly from `Ex`. [[tutorial-interoperability]] ==== Interoperability @@ -852,7 +852,7 @@ Note that if the above logic is nested (e.g. one function calling another), `new For a detailed tutorial see <>. -TIP: To avoid ambiguities, whenever possible, use the <> function template when throwing exceptions to ensure that the exception object transports a unique `error_id`; better yet, use the <> macro, which in addition will capture `pass:[__FILE__]` and `pass:[__LINE__]`. +TIP: To avoid ambiguities, whenever possible, use the <> function template to throw exceptions, to ensure that the exception object transports a unique `error_id`; better yet, use the <> macro, which in addition will capture `pass:[__FILE__]` and `pass:[__LINE__]`. ''' @@ -1015,20 +1015,20 @@ void read_file(FILE * f) { .... size_t nr1=fread(buf1,1,count1,f); if( ferror(f) ) - throw leaf::exception(); + leaf::throw_exception(); size_t nr2=fread(buf2,1,count2,f); if( ferror(f) ) - throw leaf::exception(); + leaf::throw_exception(); size_t nr3=fread(buf3,1,count3,f); if( ferror(f) ) - throw leaf::exception(); + leaf::throw_exception(); .... } ---- -Above, if a `throw` statement is reached, LEAF will invoke the function passed to `on_error` and associate the returned `e_errno` object with the exception. +Above, if `throw_exception` is called, LEAF will invoke the function passed to `on_error` and associate the returned `e_errno` object with the exception. The final argument type that can be passed to `on_error` is a function that takes a single mutable error object reference. In this case, `on_error` uses it similarly to how such functions are used by `load`; see <>. @@ -1564,7 +1564,7 @@ leaf::result file_read( FILE & f, void * buf, int size ) <2> In addition, this error is classified as `read_error`. <3> In addition, this error is classified as `eof_error`. -This technique works just as well if we choose to use exception handling, we just call `leaf::exception` instead of `leaf::new_error`: +This technique works just as well if we choose to use exception handling, we just call `leaf::throw_exception` instead of `leaf::new_error`: [source,c++] ---- @@ -1575,16 +1575,16 @@ void file_read( FILE & f, void * buf, int size ) int n = fread(buf, 1, size, &f); if( ferror(&f) ) - throw leaf::exception(read_error{}, leaf::e_errno{errno}); + leaf::throw_exception(read_error{}, leaf::e_errno{errno}); if( n!=size ) - throw leaf::exception(eof_error{}); + leaf::throw_exception(eof_error{}); } ---- [.text-right] -<> | <> | <> +<> | <> | <> -NOTE: If the type of the first argument passed to `leaf::exception` derives from `std::exception`, it will be used to initialize the returned exception object taken by `throw`. Here this is not the case, so the function returns a default-initialized `std::exception` object, while the first (and any other) argument is associated with the failure. +NOTE: If the type of the first argument passed to `leaf::throw_exception` derives from `std::exception`, it will be used to initialize the thrown exception object. Here this is not the case, so the function returns a default-initialized `std::exception` object, while the first (and any other) argument is associated with the failure. Now we can write a future-proof handler for any `input_error`: @@ -2389,7 +2389,7 @@ namespace boost { namespace leaf { else\ return <>.error() -#define BOOST_LEAF_NEW_ERROR <> ::boost::leaf::new_error +#define BOOST_LEAF_NEW_ERROR <> ---- [.text-right] @@ -2588,33 +2588,31 @@ Reference: <> | <> namespace boost { namespace leaf { template <1> - <> exception( Ex &&, E && ... ) noexcept; + [[noreturn]] void throw_exception( Ex &&, E && ... ); template <2> - <> exception( E1 &&, E && ... ) noexcept; + [[noreturn]] void throw_exception( E1 &&, E && ... ); - <> exception() noexcept; + [[noreturn]] void throw_exception(); template <1> - <> exception( error_id id, Ex &&, E && ... ) noexcept; + [[noreturn]] void throw_exception( error_id id, Ex &&, E && ... ); template <2> - <> exception( error_id id, E1 &&, E && ... ) noexcept; + [[noreturn]] void throw_exception( error_id id, E1 &&, E && ... ); - <> exception( error_id id ) noexcept; + [[noreturn]] void throw_exception( error_id id ); template <-deduced>> exception_to_result( F && f ) noexcept; } } -#define BOOST_LEAF_EXCEPTION <> ::boost::leaf::exception - -#define BOOST_LEAF_THROW_EXCEPTION <> ::boost::leaf::exception +#define BOOST_LEAF_THROW_EXCEPTION <> ---- [.text-right] -Reference: <> | <> | <> +Reference: <> | <> <1> Only enabled if std::is_base_of::value. <2> Only enabled if !std::is_base_of::value. @@ -3025,8 +3023,8 @@ TIP: See also <>. ''' -[[exception]] -=== `exception` +[[throw_exception]] +=== `throw_exception` [source,c++] .#include @@ -3034,57 +3032,57 @@ TIP: See also <>. namespace boost { namespace leaf { template <1> - <> exception( Ex && ex, E && ... e ) noexcept; + [[noreturn]] void throw_exception( Ex && ex, E && ... e ); template <2> - <> exception( E1 && e1, E && ... e ) noexcept; + [[noreturn]] void throw_exception( E1 && e1, E && ... e ); - <> exception() noexcept; <3> + [[noreturn]] void throw_exception(); <3> template <4> - <> exception( error_id id, Ex && ex, E && ... e ) noexcept; + [[noreturn]] void throw_exception( error_id id, Ex && ex, E && ... e ); template <5> - <> exception( error_id id, E1 && e1, E && ... e ) noexcept; + [[noreturn]] void throw_exception( error_id id, E1 && e1, E && ... e ); - <> exception( error_id id ) noexcept; <6> + [[noreturn]] void throw_exception( error_id id ); <6> } } ---- -The `exception` function is overloaded: it can be invoked with no arguments, or else there are several alternatives, selected using `std::enable_if` based on the type of the passed arguments: +The `throw_exception` function is overloaded: it can be invoked with no arguments, or else there are several alternatives, selected using `std::enable_if` based on the type of the passed arguments. All overloads throw an exception: -<1> Selected if the first argument is not of type `error_id` and is an exception object, that is, iff `Ex` derives publicly from `std::exception`. In this case the return value is of unspecified type which derives publicly from `Ex` *and* from class <>, such that: +<1> Selected if the first argument is not of type `error_id` and is an exception object, that is, iff `Ex` derives publicly from `std::exception`. In this case the thrown exception is of unspecified type which derives publicly from `Ex` *and* from class <>, such that: * its `Ex` subobject is initialized by `std::forward(ex)`; * its `error_id` subobject is initialized by `<>(std::forward(e)...`). -<2> Selected if the first argument is not of type `error_id` and is not an exception object. In this case the return value is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: +<2> Selected if the first argument is not of type `error_id` and is not an exception object. In this case the thrown exception is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: ** its `std::exception` subobject is default-initialized; ** its `error_id` subobject is initialized by `<>(std::forward(e1), std::forward(e)...`). -<3> If the fuction is invoked without arguments, the return value is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: +<3> If the fuction is invoked without arguments, the thrown exception is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: ** its `std::exception` subobject is default-initialized; ** its `error_id` subobject is initialized by `<>()`. -<4> Selected if the first argument is of type `error_id` and the second argument is an exception object, that is, iff `Ex` derives publicly from `std::exception`. In this case the return value is of unspecified type which derives publicly from `Ex` *and* from class <>, such that: +<4> Selected if the first argument is of type `error_id` and the second argument is an exception object, that is, iff `Ex` derives publicly from `std::exception`. In this case the thrown exception is of unspecified type which derives publicly from `Ex` *and* from class <>, such that: ** its `Ex` subobject is initialized by `std::forward(ex)`; ** its `error_id` subobject is initialized by `id.<>(std::forward(e)...)`. -<5> Selected if the first argument is of type `error_id` and the second argument is not an exception object. In this case the return value is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: +<5> Selected if the first argument is of type `error_id` and the second argument is not an exception object. In this case the thrown exception is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: ** its `std::exception` subobject is default-initialized; ** its `error_id` subobject is initialized by `id.<>(std::forward(e1), std::forward(e)...`). -<6> If `exception` is invoked with just an `error_id` object, the return value is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: +<6> If `exception` is invoked with just an `error_id` object, the thrown exception is of unspecified type which derives publicly from `std::exception` *and* from class `error_id`, such that: ** its `std::exception` subobject is default-initialized; ** its `error_id` subobject is initialized by copying from `id`. -NOTE: The first three overloads return an exception object that is associated with a new `error_id`. The second three overloads return an exception object that is associated with the specified `error_id`. +NOTE: The first three overloads throw an exception object that is associated with a new `error_id`. The second three overloads throw an exception object that is associated with the specified `error_id`. .Example 1: [source,c++] ---- struct my_exception: std::exception { }; -throw leaf::exception(my_exception{}); <1> +leaf::throw_exception(my_exception{}); <1> ---- <1> Throws an exception of a type that derives from `error_id` and from `my_exception` (because `my_exception` derives from `std::exception`). @@ -3093,11 +3091,11 @@ throw leaf::exception(my_exception{}); <1> ---- enum class my_error { e1=1, e2, e3 }; <1> -throw leaf::exception(my_error::e1); +leaf::throw_exception(my_error::e1); ---- <1> Throws an exception of a type that derives from `error_id` and from `std::exception` (because `my_error` does not derive from `std::exception`). -NOTE: To automatically capture `pass:[__FILE__]`, `pass:[__LINE__]` and `pass:[__FUNCTION__]` with the returned object, use <> instead of `leaf::exception`. +NOTE: To automatically capture `pass:[__FILE__]`, `pass:[__LINE__]` and `pass:[__FUNCTION__]` with the returned object, use <> instead of `leaf::throw_exception`. ''' @@ -4315,7 +4313,7 @@ namespace boost { namespace leaf { } } ---- -The <>, <> and <> macros capture `pass:[__FILE__]`, `pass:[__LINE__]` and `pass:[__FUNCTION__]` into a `e_source_location` object. +The <> and <> macros capture `pass:[__FILE__]`, `pass:[__LINE__]` and `pass:[__FUNCTION__]` into a `e_source_location` object. ''' @@ -5524,16 +5522,16 @@ If `BOOST_LEAF_CFG_GNUC_STMTEXPR` is `1` (which is the default under `pass:[__GN ''' -[[BOOST_LEAF_EXCEPTION]] -=== `BOOST_LEAF_EXCEPTION` +[[BOOST_LEAF_THROW_EXCEPTION]] +=== `BOOST_LEAF_THROW_EXCEPTION` [source,c++] .#include ---- -#define BOOST_LEAF_EXCEPTION <> +#define BOOST_LEAF_THROW_EXCEPTION <> ---- -Effects: :: `BOOST_LEAF_EXCEPTION(e...)` is equivalent to `leaf::<>(e...)`, except the current source location is automatically passed, in a `<>` object (in addition to all `e...` objects). +Effects: :: `BOOST_LEAF_THROW_EXCEPTION(e...)` is equivalent to `leaf::<>(e...)`, except the current source location is automatically communicated with the thrown exception, in a `<>` object (in addition to all `e...` objects). ''' @@ -5543,24 +5541,11 @@ Effects: :: `BOOST_LEAF_EXCEPTION(e...)` is equivalent to `leaf::< [source,c++] ---- -#define BOOST_LEAF_NEW_ERROR <> +#define BOOST_LEAF_NEW_ERROR <> ---- Effects: :: `BOOST_LEAF_NEW_ERROR(e...)` is equivalent to `leaf::<>(e...)`, except the current source location is automatically passed, in a `<>` object (in addition to all `e...` objects). -''' - -[[BOOST_LEAF_THROW_EXCEPTION]] -=== `BOOST_LEAF_THROW_EXCEPTION` - -[source,c++] -.#include ----- -#define BOOST_LEAF_THROW_EXCEPTION throw BOOST_LEAF_EXCEPTION ----- - -Effects: :: Throws the exception object returned by <>. - [[rationale]] == Design @@ -5943,12 +5928,12 @@ https://www.boost.org/doc/libs/release/libs/exception/doc/exception_operator_shl | [source,c++,options="nowrap"] ---- -throw leaf::exception( my_exception(), +leaf::throw_exception( my_exception(), my_info{x}, my_info{y} ); ---- [.text-right] -<> +<> |==== .Augmenting exceptions in error neutral contexts diff --git a/example/asio_beast_leaf_rpc.cpp b/example/asio_beast_leaf_rpc.cpp index 8201a2a..8fc357d 100644 --- a/example/asio_beast_leaf_rpc.cpp +++ b/example/asio_beast_leaf_rpc.cpp @@ -376,7 +376,7 @@ leaf::result execute_command(std::string_view line) { if (i2 == 0) { // In some cases this command execution function might throw, not // just return an error. - throw leaf::exception(std::runtime_error{"division by zero"}); + leaf::throw_exception(std::runtime_error{"division by zero"}); } response = std::to_string(i1 % i2); } else { diff --git a/example/capture_in_exception.cpp b/example/capture_in_exception.cpp index c203aff..3652ce7 100644 --- a/example/capture_in_exception.cpp +++ b/example/capture_in_exception.cpp @@ -33,7 +33,7 @@ task_result task() if( succeed ) return { }; else - throw leaf::exception( + leaf::throw_exception( e_thread_id{std::this_thread::get_id()}, e_failure_info1{"info"}, e_failure_info2{42} ); diff --git a/example/lua_callback_eh.cpp b/example/lua_callback_eh.cpp index 4e87f26..00f62c3 100644 --- a/example/lua_callback_eh.cpp +++ b/example/lua_callback_eh.cpp @@ -75,7 +75,7 @@ int do_work( lua_State * L ) } else { - throw leaf::exception(ec1); + leaf::throw_exception(ec1); } } @@ -127,7 +127,7 @@ int call_lua( lua_State * L ) // cur_err.assigned_error_id() will return a new leaf::error_id, // otherwise we'll be working with the original error reported // by a C++ exception out of do_work. - throw leaf::exception( cur_err.assigned_error_id().load( e_lua_pcall_error{err}, e_lua_error_message{std::move(msg)} ) ); + leaf::throw_exception( cur_err.assigned_error_id().load( e_lua_pcall_error{err}, e_lua_error_message{std::move(msg)} ) ); } else { diff --git a/example/print_file/print_file_eh.cpp b/example/print_file/print_file_eh.cpp index 69361e4..f89c9a5 100644 --- a/example/print_file/print_file_eh.cpp +++ b/example/print_file/print_file_eh.cpp @@ -67,7 +67,7 @@ int main( int argc, char const * argv[] ) std::cout << buffer; std::cout.flush(); if( std::cout.fail() ) - throw leaf::exception(output_error, leaf::e_errno{errno}); + leaf::throw_exception(output_error, leaf::e_errno{errno}); return 0; }, @@ -152,7 +152,7 @@ char const * parse_command_line( int argc, char const * argv[] ) if( argc==2 ) return argv[1]; else - throw leaf::exception(bad_command_line); + leaf::throw_exception(bad_command_line); } @@ -162,7 +162,7 @@ std::shared_ptr file_open( char const * file_name ) if( FILE * f = fopen(file_name, "rb") ) return std::shared_ptr(f, &fclose); else - throw leaf::exception(open_error, leaf::e_errno{errno}); + leaf::throw_exception(open_error, leaf::e_errno{errno}); } @@ -172,14 +172,14 @@ int file_size( FILE & f ) auto load = leaf::on_error([] { return leaf::e_errno{errno}; }); if( fseek(&f, 0, SEEK_END) ) - throw leaf::exception(size_error); + leaf::throw_exception(size_error); int s = ftell(&f); if( s==-1L ) - throw leaf::exception(size_error); + leaf::throw_exception(size_error); if( fseek(&f,0,SEEK_SET) ) - throw leaf::exception(size_error); + leaf::throw_exception(size_error); return s; } @@ -191,8 +191,8 @@ void file_read( FILE & f, void * buf, int size ) int n = fread(buf, 1, size, &f); if( ferror(&f) ) - throw leaf::exception(read_error, leaf::e_errno{errno}); + leaf::throw_exception(read_error, leaf::e_errno{errno}); if( n!=size ) - throw leaf::exception(eof_error); + leaf::throw_exception(eof_error); } diff --git a/include/boost/leaf/capture.hpp b/include/boost/leaf/capture.hpp index 6455eb2..b26be0f 100644 --- a/include/boost/leaf/capture.hpp +++ b/include/boost/leaf/capture.hpp @@ -132,12 +132,12 @@ namespace leaf_detail catch( exception_base const & e ) { ctx->captured_id_ = e.get_error_id(); - throw_exception( capturing_exception(std::current_exception(), std::move(ctx)) ); + leaf_detail::throw_exception_impl( capturing_exception(std::current_exception(), std::move(ctx)) ); } catch(...) { ctx->captured_id_ = cur_err.assigned_error_id(); - throw_exception( capturing_exception(std::current_exception(), std::move(ctx)) ); + leaf_detail::throw_exception_impl( capturing_exception(std::current_exception(), std::move(ctx)) ); } } @@ -165,12 +165,12 @@ namespace leaf_detail catch( exception_base const & e ) { ctx->captured_id_ = e.get_error_id(); - throw_exception( capturing_exception(std::current_exception(), std::move(ctx)) ); + leaf_detail::throw_exception_impl( capturing_exception(std::current_exception(), std::move(ctx)) ); } catch(...) { ctx->captured_id_ = cur_err.assigned_error_id(); - throw_exception( capturing_exception(std::current_exception(), std::move(ctx)) ); + leaf_detail::throw_exception_impl( capturing_exception(std::current_exception(), std::move(ctx)) ); } } diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index b8c7685..947792b 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -99,39 +99,6 @@ namespace leaf_detail //////////////////////////////////////// -#ifdef BOOST_LEAF_NO_EXCEPTIONS - -namespace boost -{ -[[noreturn]] void throw_exception( std::exception const & ); // user defined -} - -namespace boost { namespace leaf { - -template -[[noreturn]] void throw_exception( T const & e ) -{ - ::boost::throw_exception(e); -} - -} } - -#else - -namespace boost { namespace leaf { - -template -[[noreturn]] void throw_exception( T const & e ) -{ - throw e; -} - -} } - -#endif - -//////////////////////////////////////// - namespace boost { namespace leaf { #if BOOST_LEAF_CFG_DIAGNOSTICS diff --git a/include/boost/leaf/exception.hpp b/include/boost/leaf/exception.hpp index bda4dd7..dc2ea56 100644 --- a/include/boost/leaf/exception.hpp +++ b/include/boost/leaf/exception.hpp @@ -8,48 +8,58 @@ #include #include - -#ifndef BOOST_LEAF_NO_EXCEPTIONS - #include -#define BOOST_LEAF_EXCEPTION ::boost::leaf::leaf_detail::inject_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::exception -#define BOOST_LEAF_THROW_EXCEPTION ::boost::leaf::leaf_detail::throw_with_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::exception +#ifdef BOOST_LEAF_NO_EXCEPTIONS -//////////////////////////////////////// +namespace boost +{ + [[noreturn]] void throw_exception( std::exception const & ); // user defined +} namespace boost { namespace leaf { namespace leaf_detail { - struct throw_with_loc + template + [[noreturn]] void throw_exception_impl( T && e ) { - char const * const file; - int const line; - char const * const fn; + ::boost::throw_exception(std::move(e)); + } - template - [[noreturn]] friend void operator+( throw_with_loc loc, Ex const & ex ) - { - ex.load_source_location_(loc.file, loc.line, loc.fn); - ::boost::leaf::throw_exception(ex); - } + class BOOST_LEAF_SYMBOL_VISIBLE exception_base + { + public: + + virtual error_id get_error_id() const noexcept = 0; + + protected: + + exception_base() noexcept { } + ~exception_base() noexcept { } }; } } } -//////////////////////////////////////// +#else + +#include namespace boost { namespace leaf { namespace leaf_detail { - inline void enforce_std_exception( std::exception const & ) noexcept { } + template + [[noreturn]] void throw_exception_impl( T && e ) + { + throw std::move(e); + } class BOOST_LEAF_SYMBOL_VISIBLE exception_base { std::shared_ptr auto_id_bump_; + public: virtual error_id get_error_id() const noexcept = 0; @@ -63,6 +73,44 @@ namespace leaf_detail ~exception_base() noexcept { } }; +} + +} } + +#endif + +//////////////////////////////////////// + +#define BOOST_LEAF_THROW_EXCEPTION ::boost::leaf::leaf_detail::throw_with_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::leaf_detail::make_exception + +namespace boost { namespace leaf { + +namespace leaf_detail +{ + struct throw_with_loc + { + char const * const file; + int const line; + char const * const fn; + + template + [[noreturn]] friend void operator+( throw_with_loc loc, Ex && ex ) + { + ex.load_source_location_(loc.file, loc.line, loc.fn); + ::boost::leaf::leaf_detail::throw_exception_impl(std::move(ex)); + } + }; +} + +} } + +//////////////////////////////////////// + +namespace boost { namespace leaf { + +namespace leaf_detail +{ + inline void enforce_std_exception( std::exception const & ) noexcept { } template class BOOST_LEAF_SYMBOL_VISIBLE exception: @@ -112,52 +160,62 @@ namespace leaf_detail { constexpr static const bool value = std::is_base_of::type>::value || at_least_one_derives_from_std_exception::value; }; + + template + inline + typename std::enable_if::type>::value, exception::type>>::type + make_exception( error_id err, Ex && ex, E && ... e ) noexcept + { + static_assert(!at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); + return exception::type>( err.load(std::forward(e)...), std::forward(ex) ); + } + + template + inline + typename std::enable_if::type>::value, exception>::type + make_exception( error_id err, E1 && car, E && ... cdr ) noexcept + { + static_assert(!at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); + return exception( err.load(std::forward(car), std::forward(cdr)...) ); + } + + inline exception make_exception( error_id err ) noexcept + { + return exception(err); + } + + template + inline + typename std::enable_if::type>::value, exception::type>>::type + make_exception( Ex && ex, E && ... e ) noexcept + { + static_assert(!at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); + return exception::type>( new_error().load(std::forward(e)...), std::forward(ex) ); + } + + template + inline + typename std::enable_if::type>::value, exception>::type + make_exception( E1 && car, E && ... cdr ) noexcept + { + static_assert(!at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); + return exception( new_error().load(std::forward(car), std::forward(cdr)...) ); + } + + inline exception make_exception() noexcept + { + return exception(leaf::new_error()); + } } -template -inline -typename std::enable_if::type>::value, leaf_detail::exception::type>>::type -exception( error_id err, Ex && ex, E && ... e ) noexcept +template +[[noreturn]] void throw_exception( E && ... e ) { - static_assert(!leaf_detail::at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); - return leaf_detail::exception::type>( err.load(std::forward(e)...), std::forward(ex) ); -} - -template -inline -typename std::enable_if::type>::value, leaf_detail::exception>::type -exception( error_id err, E1 && car, E && ... cdr ) noexcept -{ - static_assert(!leaf_detail::at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); - return leaf_detail::exception( err.load(std::forward(car), std::forward(cdr)...) ); -} - -inline leaf_detail::exception exception( error_id err ) noexcept -{ - return leaf_detail::exception(err); -} - -template -inline -typename std::enable_if::type>::value, leaf_detail::exception::type>>::type -exception( Ex && ex, E && ... e ) noexcept -{ - static_assert(!leaf_detail::at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); - return leaf_detail::exception::type>( new_error().load(std::forward(e)...), std::forward(ex) ); -} - -template -inline -typename std::enable_if::type>::value, leaf_detail::exception>::type -exception( E1 && car, E && ... cdr ) noexcept -{ - static_assert(!leaf_detail::at_least_one_derives_from_std_exception::value, "Error objects passed to leaf::exception may not derive from std::exception"); - return leaf_detail::exception( new_error().load(std::forward(car), std::forward(cdr)...) ); -} - -inline leaf_detail::exception exception() noexcept -{ - return leaf_detail::exception(leaf::new_error()); + // Warning: setting a breakpoint here will not intercept exceptions thrown + // via BOOST_LEAF_THROW_EXCEPTION or originating in the few other throw + // points elsewhere in LEAF. To intercept all of those exceptions as well, + // set a breakpoint inside boost::leaf::leaf_detail::throw_exception_impl. + leaf_detail::throw_exception_impl(leaf_detail::make_exception(std::forward(e)...)); } //////////////////////////////////////// @@ -223,5 +281,3 @@ exception_to_result( F && f ) noexcept } } #endif - -#endif diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index f2ad7e1..cd983f4 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -7,7 +7,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include #include #include @@ -281,7 +281,7 @@ protected: void enforce_value_state() const { if( !has_value() ) - ::boost::leaf::throw_exception(bad_result(get_error_id())); + ::boost::leaf::leaf_detail::throw_exception_impl(bad_result(get_error_id())); } public: diff --git a/test/accumulate_nested_error_exception_test.cpp b/test/accumulate_nested_error_exception_test.cpp index 163be9a..a10dcbe 100644 --- a/test/accumulate_nested_error_exception_test.cpp +++ b/test/accumulate_nested_error_exception_test.cpp @@ -38,7 +38,7 @@ struct info void f0() { auto load = leaf::on_error( []( info<0> & ) { } ); - throw leaf::exception(info<2>{2}); + leaf::throw_exception(info<2>{2}); } void f1() diff --git a/test/accumulate_nested_new_error_exception_test.cpp b/test/accumulate_nested_new_error_exception_test.cpp index 91b2997..7486e8e 100644 --- a/test/accumulate_nested_new_error_exception_test.cpp +++ b/test/accumulate_nested_new_error_exception_test.cpp @@ -38,14 +38,14 @@ struct info void f0() { auto load = leaf::on_error( info<0>{-1} ); - throw leaf::exception(info<1>{-1}); + leaf::throw_exception(info<1>{-1}); } void f1() { auto load = leaf::on_error( []( info<0> & x ) { }, []( info<1> & x ) { ++x.value; }, []( info<2> & x ) { ++x.value; } ); try { f0(); } catch(...) { } - throw leaf::exception(); + leaf::throw_exception(); } leaf::error_id f2() diff --git a/test/capture_exception_async_test.cpp b/test/capture_exception_async_test.cpp index 57a5ea7..5825a91 100644 --- a/test/capture_exception_async_test.cpp +++ b/test/capture_exception_async_test.cpp @@ -87,7 +87,7 @@ int main() if( res >= 0 ) return res; else - throw leaf::exception(info<1>{a}, info<2>{b}, info<3>{}); + leaf::throw_exception(info<1>{a}, info<2>{b}, info<3>{}); } ); for( auto & f : fut ) @@ -122,7 +122,7 @@ int main() if( res >= 0 ) return res; else - throw leaf::exception(info<1>{a}, info<2>{b}, info<3>{}); + leaf::throw_exception(info<1>{a}, info<2>{b}, info<3>{}); } ); for( auto & f : fut ) diff --git a/test/capture_exception_state_test.cpp b/test/capture_exception_state_test.cpp index 9e3b9cf..a8a4eb2 100644 --- a/test/capture_exception_state_test.cpp +++ b/test/capture_exception_state_test.cpp @@ -69,7 +69,7 @@ int main() leaf::make_shared_context(error_handlers), [] { - throw leaf::exception(info<1>{}, info<3>{}); + leaf::throw_exception(info<1>{}, info<3>{}); } ); BOOST_TEST(false); } diff --git a/test/capture_exception_unload_test.cpp b/test/capture_exception_unload_test.cpp index c784c83..8bb548c 100644 --- a/test/capture_exception_unload_test.cpp +++ b/test/capture_exception_unload_test.cpp @@ -194,13 +194,13 @@ int main() test, info<2>, info<3>>( [] { - throw leaf::exception(info<1>{1}, info<3>{3}); // Derives from leaf::leaf::error_id + leaf::throw_exception(info<1>{1}, info<3>{3}); // Derives from leaf::leaf::error_id } ); test, info<2>, info<3>>( [] { auto load = leaf::on_error( info<1>{1}, info<3>{3} ); - throw leaf::exception(); // Derives from leaf::leaf::error_id + leaf::throw_exception(); // Derives from leaf::leaf::error_id } ); test, info<2>, info<3>>( [] diff --git a/test/defer_nested_error_exception_test.cpp b/test/defer_nested_error_exception_test.cpp index b85d3b6..887064b 100644 --- a/test/defer_nested_error_exception_test.cpp +++ b/test/defer_nested_error_exception_test.cpp @@ -38,7 +38,7 @@ struct info void f0() { auto load = leaf::on_error( [] { return info<0>{0}; } ); - throw leaf::exception(info<2>{2}); + leaf::throw_exception(info<2>{2}); } void f1() diff --git a/test/defer_nested_new_error_exception_test.cpp b/test/defer_nested_new_error_exception_test.cpp index 928d556..2b5d82c 100644 --- a/test/defer_nested_new_error_exception_test.cpp +++ b/test/defer_nested_new_error_exception_test.cpp @@ -38,14 +38,14 @@ struct info void f0() { auto load = leaf::on_error( [] { return info<0>{-1}; } ); - throw leaf::exception(info<1>{-1}); + leaf::throw_exception(info<1>{-1}); } void f1() { auto load = leaf::on_error( [] { return info<0>{0}; }, [] { return info<1>{1}; }, [] { return info<2>{2}; } ); try { f0(); } catch(...) { } - throw leaf::exception(); + leaf::throw_exception(); } leaf::error_id f2() diff --git a/test/diagnostic_info_test2.cpp b/test/diagnostic_info_test2.cpp index fbbae7a..ef50ee5 100644 --- a/test/diagnostic_info_test2.cpp +++ b/test/diagnostic_info_test2.cpp @@ -73,12 +73,12 @@ int main() leaf::try_catch( [] { - throw leaf::exception(info<1>{}); + leaf::throw_exception(info<1>{}); }, [] { } ); - throw leaf::exception(info<2>{}); + leaf::throw_exception(info<2>{}); }, []( info<1> ) { diff --git a/test/exception_test.cpp b/test/exception_test.cpp index 50949b5..91f912e 100644 --- a/test/exception_test.cpp +++ b/test/exception_test.cpp @@ -118,92 +118,76 @@ int test( F && f ) int main() { BOOST_TEST_EQ(20, test>([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(20, test>([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test>([]{ throw leaf::exception(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test>([]{ my_exception exc(42); throw leaf::exception(exc, info{42}); })); - BOOST_TEST_EQ(21, test>([]{ my_exception const exc(42); throw leaf::exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test>([]{ leaf::throw_exception(my_exception(42), info{42}); })); + BOOST_TEST_EQ(21, test>([]{ my_exception exc(42); leaf::throw_exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test>([]{ my_exception const exc(42); leaf::throw_exception(exc, info{42}); })); BOOST_TEST_EQ(22, test>([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(22, test>([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(23, test>([]{ throw leaf::exception(my_exception(42)); })); - BOOST_TEST_EQ(23, test>([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test>([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(23, test>([]{ leaf::throw_exception(my_exception(42)); })); + BOOST_TEST_EQ(23, test>([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test>([]{ my_exception const exc(42); leaf::throw_exception(exc); })); BOOST_TEST_EQ(20, test([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(20, test([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test([]{ throw leaf::exception(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test([]{ my_exception exc(42); throw leaf::exception(exc, info{42}); })); - BOOST_TEST_EQ(21, test([]{ my_exception const exc(42); throw leaf::exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test([]{ leaf::throw_exception(my_exception(42), info{42}); })); + BOOST_TEST_EQ(21, test([]{ my_exception exc(42); leaf::throw_exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test([]{ my_exception const exc(42); leaf::throw_exception(exc, info{42}); })); BOOST_TEST_EQ(22, test([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(22, test([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(23, test([]{ throw leaf::exception(my_exception(42)); })); - BOOST_TEST_EQ(23, test([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(23, test([]{ leaf::throw_exception(my_exception(42)); })); + BOOST_TEST_EQ(23, test([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); leaf::throw_exception(exc); })); BOOST_TEST_EQ(40, test([]{ BOOST_LEAF_THROW_EXCEPTION(info{42}); })); - BOOST_TEST_EQ(40, test([]{ throw BOOST_LEAF_EXCEPTION(info{42}); })); - BOOST_TEST_EQ(41, test([]{ throw leaf::exception(info{42}); })); - BOOST_TEST_EQ(41, test([]{ info inf{42}; throw leaf::exception(inf); })); - BOOST_TEST_EQ(41, test([]{ info const inf{42}; throw leaf::exception(inf); })); + BOOST_TEST_EQ(41, test([]{ leaf::throw_exception(info{42}); })); + BOOST_TEST_EQ(41, test([]{ info inf{42}; leaf::throw_exception(inf); })); + BOOST_TEST_EQ(41, test([]{ info const inf{42}; leaf::throw_exception(inf); })); BOOST_TEST_EQ(42, test([]{ BOOST_LEAF_THROW_EXCEPTION(); })); - BOOST_TEST_EQ(42, test([]{ throw BOOST_LEAF_EXCEPTION(); })); - BOOST_TEST_EQ(43, test([]{ throw leaf::exception(); })); - BOOST_TEST_EQ(23, test([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(43, test([]{ leaf::throw_exception(); })); + BOOST_TEST_EQ(23, test([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); leaf::throw_exception(exc); })); BOOST_TEST_EQ(20, test([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(20, test([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test([]{ throw leaf::exception(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test([]{ my_exception exc(42); throw leaf::exception(exc, info{42}); })); - BOOST_TEST_EQ(21, test([]{ my_exception const exc(42); throw leaf::exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test([]{ leaf::throw_exception(my_exception(42), info{42}); })); + BOOST_TEST_EQ(21, test([]{ my_exception exc(42); leaf::throw_exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test([]{ my_exception const exc(42); leaf::throw_exception(exc, info{42}); })); BOOST_TEST_EQ(22, test([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(22, test([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(23, test([]{ throw leaf::exception(my_exception(42)); })); - BOOST_TEST_EQ(23, test([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(23, test([]{ leaf::throw_exception(my_exception(42)); })); + BOOST_TEST_EQ(23, test([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); leaf::throw_exception(exc); })); BOOST_TEST_EQ(40, test([]{ BOOST_LEAF_THROW_EXCEPTION(info{42}); })); - BOOST_TEST_EQ(40, test([]{ throw BOOST_LEAF_EXCEPTION(info{42}); })); - BOOST_TEST_EQ(41, test([]{ throw leaf::exception(info{42}); })); - BOOST_TEST_EQ(41, test([]{ info inf{42}; throw leaf::exception(inf); })); - BOOST_TEST_EQ(41, test([]{ info const inf{42}; throw leaf::exception(inf); })); + BOOST_TEST_EQ(41, test([]{ leaf::throw_exception(info{42}); })); + BOOST_TEST_EQ(41, test([]{ info inf{42}; leaf::throw_exception(inf); })); + BOOST_TEST_EQ(41, test([]{ info const inf{42}; leaf::throw_exception(inf); })); BOOST_TEST_EQ(42, test([]{ BOOST_LEAF_THROW_EXCEPTION(); })); - BOOST_TEST_EQ(42, test([]{ throw BOOST_LEAF_EXCEPTION(); })); - BOOST_TEST_EQ(43, test([]{ throw leaf::exception(); })); - BOOST_TEST_EQ(23, test([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(43, test([]{ leaf::throw_exception(); })); + BOOST_TEST_EQ(23, test([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); leaf::throw_exception(exc); })); BOOST_TEST_EQ(20, test>([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(20, test>([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test>([]{ throw leaf::exception(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test>([]{ my_exception exc(42); throw leaf::exception(exc, info{42}); })); - BOOST_TEST_EQ(21, test>([]{ my_exception const exc(42); throw leaf::exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test>([]{ leaf::throw_exception(my_exception(42), info{42}); })); + BOOST_TEST_EQ(21, test>([]{ my_exception exc(42); leaf::throw_exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test>([]{ my_exception const exc(42); leaf::throw_exception(exc, info{42}); })); BOOST_TEST_EQ(22, test>([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(22, test>([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(23, test>([]{ throw leaf::exception(my_exception(42)); })); - BOOST_TEST_EQ(23, test>([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test>([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(23, test>([]{ leaf::throw_exception(my_exception(42)); })); + BOOST_TEST_EQ(23, test>([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test>([]{ my_exception const exc(42); leaf::throw_exception(exc); })); BOOST_TEST_EQ(20, test([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(20, test([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test([]{ throw leaf::exception(my_exception(42), info{42}); })); - BOOST_TEST_EQ(21, test([]{ my_exception exc(42); throw leaf::exception(exc, info{42}); })); - BOOST_TEST_EQ(21, test([]{ my_exception const exc(42); throw leaf::exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test([]{ leaf::throw_exception(my_exception(42), info{42}); })); + BOOST_TEST_EQ(21, test([]{ my_exception exc(42); leaf::throw_exception(exc, info{42}); })); + BOOST_TEST_EQ(21, test([]{ my_exception const exc(42); leaf::throw_exception(exc, info{42}); })); BOOST_TEST_EQ(22, test([]{ BOOST_LEAF_THROW_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(22, test([]{ throw BOOST_LEAF_EXCEPTION(my_exception(42)); })); - BOOST_TEST_EQ(23, test([]{ throw leaf::exception(my_exception(42)); })); - BOOST_TEST_EQ(23, test([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(23, test([]{ leaf::throw_exception(my_exception(42)); })); + BOOST_TEST_EQ(23, test([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); leaf::throw_exception(exc); })); BOOST_TEST_EQ(40, test([]{ BOOST_LEAF_THROW_EXCEPTION(info{42}); })); - BOOST_TEST_EQ(40, test([]{ throw BOOST_LEAF_EXCEPTION(info{42}); })); - BOOST_TEST_EQ(41, test([]{ throw leaf::exception(info{42}); })); - BOOST_TEST_EQ(41, test([]{ info inf{42}; throw leaf::exception(inf); })); - BOOST_TEST_EQ(41, test([]{ info const inf{42}; throw leaf::exception(inf); })); + BOOST_TEST_EQ(41, test([]{ leaf::throw_exception(info{42}); })); + BOOST_TEST_EQ(41, test([]{ info inf{42}; leaf::throw_exception(inf); })); + BOOST_TEST_EQ(41, test([]{ info const inf{42}; leaf::throw_exception(inf); })); BOOST_TEST_EQ(42, test([]{ BOOST_LEAF_THROW_EXCEPTION(); })); - BOOST_TEST_EQ(42, test([]{ throw BOOST_LEAF_EXCEPTION(); })); - BOOST_TEST_EQ(43, test([]{ throw leaf::exception(); })); - BOOST_TEST_EQ(23, test([]{ my_exception exc(42); throw leaf::exception(exc); })); - BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); throw leaf::exception(exc); })); + BOOST_TEST_EQ(43, test([]{ leaf::throw_exception(); })); + BOOST_TEST_EQ(23, test([]{ my_exception exc(42); leaf::throw_exception(exc); })); + BOOST_TEST_EQ(23, test([]{ my_exception const exc(42); leaf::throw_exception(exc); })); { char const * wh = 0; @@ -283,7 +267,7 @@ int main() leaf::try_catch( [] { - throw leaf::exception( info{42} ); + leaf::throw_exception( info{42} ); }, []( info x ) { diff --git a/test/multiple_errors_test.cpp b/test/multiple_errors_test.cpp index da1e74e..1e6718d 100644 --- a/test/multiple_errors_test.cpp +++ b/test/multiple_errors_test.cpp @@ -68,7 +68,7 @@ int main() { try { - throw leaf::exception(info<4>{4}); + leaf::throw_exception(info<4>{4}); } catch(...) { diff --git a/test/preload_exception_test.cpp b/test/preload_exception_test.cpp index 8008d14..231f4f6 100644 --- a/test/preload_exception_test.cpp +++ b/test/preload_exception_test.cpp @@ -67,7 +67,7 @@ int main() leaf::try_catch( [] { - f1( [] { throw leaf::exception(); } ); + f1( [] { leaf::throw_exception(); } ); return 0; }, []( leaf::error_info const & err, info<1> ) @@ -88,7 +88,7 @@ int main() leaf::try_catch( [] { - f2( [] { throw leaf::exception(); } ); + f2( [] { leaf::throw_exception(); } ); return 0; }, []( info<1> ) diff --git a/test/preload_nested_error_exception_test.cpp b/test/preload_nested_error_exception_test.cpp index 301daae..eae593f 100644 --- a/test/preload_nested_error_exception_test.cpp +++ b/test/preload_nested_error_exception_test.cpp @@ -38,7 +38,7 @@ struct info void f0() { auto load = leaf::on_error( info<0>{0} ); - throw leaf::exception(info<2>{2}); + leaf::throw_exception(info<2>{2}); } void f1() diff --git a/test/preload_nested_new_error_exception_test.cpp b/test/preload_nested_new_error_exception_test.cpp index 4a593e8..bf4560e 100644 --- a/test/preload_nested_new_error_exception_test.cpp +++ b/test/preload_nested_new_error_exception_test.cpp @@ -38,14 +38,14 @@ struct info void f0() { auto load = leaf::on_error( info<0>{-1} ); - throw leaf::exception(info<1>{-1}); + leaf::throw_exception(info<1>{-1}); } void f1() { auto load = leaf::on_error( info<0>{}, info<1>{1}, info<2>{2} ); try { f0(); } catch(...) { } - throw leaf::exception(); + leaf::throw_exception(); } leaf::error_id f2() diff --git a/test/try_catch_error_id_test.cpp b/test/try_catch_error_id_test.cpp index 5b32875..2714159 100644 --- a/test/try_catch_error_id_test.cpp +++ b/test/try_catch_error_id_test.cpp @@ -38,7 +38,7 @@ int main() int r = leaf::try_catch( []() -> int { - throw leaf::exception( my_error(), info{42} ); + leaf::throw_exception( my_error(), info{42} ); }, []( my_error const & x, leaf::catch_ id ) { diff --git a/test/try_catch_system_error_test.cpp b/test/try_catch_system_error_test.cpp index 2ece5fd..ad3abd5 100644 --- a/test/try_catch_system_error_test.cpp +++ b/test/try_catch_system_error_test.cpp @@ -38,7 +38,7 @@ int main() int r = leaf::try_catch( []() -> int { - throw leaf::exception( std::system_error(make_error_code(errc_a::a0)), info{42} ); + leaf::throw_exception( std::system_error(make_error_code(errc_a::a0)), info{42} ); }, []( std::system_error const & se, leaf::match_value ) { @@ -74,7 +74,7 @@ int main() int r = leaf::try_catch( []() -> int { - throw leaf::exception( std::system_error(make_error_code(errc_a::a0)), info{42} ); + leaf::throw_exception( std::system_error(make_error_code(errc_a::a0)), info{42} ); }, []( leaf::match, errc_a::a0> code, leaf::match_value ) { @@ -112,7 +112,7 @@ int main() int r = leaf::try_catch( []() -> int { - throw leaf::exception( std::system_error(make_error_code(errc_a::a0)), info{42} ); + leaf::throw_exception( std::system_error(make_error_code(errc_a::a0)), info{42} ); }, []( std::error_code const & ec, leaf::match_value ) { diff --git a/test/try_catch_test.cpp b/test/try_catch_test.cpp index d14740f..2e3b242 100644 --- a/test/try_catch_test.cpp +++ b/test/try_catch_test.cpp @@ -45,7 +45,7 @@ struct exc_val: std::exception { int value; explicit exc_val(int v): value(v) { template R failing( Ex && ex ) { - throw leaf::exception(std::move(ex), info<1>{1}, info<2>{2}, info<3>{3}); + leaf::throw_exception(std::move(ex), info<1>{1}, info<2>{2}, info<3>{3}); } template @@ -549,7 +549,7 @@ int main() int r = leaf::try_catch( [] { - throw leaf::exception(exc_val{42}); + leaf::throw_exception(exc_val{42}); return 0; }, []( leaf::match_value ) @@ -566,7 +566,7 @@ int main() int r = leaf::try_catch( [] { - throw leaf::exception(exc_val{42}); + leaf::throw_exception(exc_val{42}); return 0; }, []( leaf::match_value ) diff --git a/test/try_exception_and_result_test.cpp b/test/try_exception_and_result_test.cpp index 954ab09..57d62ef 100644 --- a/test/try_exception_and_result_test.cpp +++ b/test/try_exception_and_result_test.cpp @@ -65,7 +65,7 @@ int main() leaf::result r = leaf::try_handle_some( []() -> leaf::result { - throw leaf::exception( my_exception(), info<1>{1} ); + leaf::throw_exception( my_exception(), info<1>{1} ); }, []( my_exception const &, info<1> const & x ) { @@ -79,7 +79,7 @@ int main() leaf::result r = leaf::try_handle_some( []() -> leaf::result { - throw leaf::exception( info<1>{1} ); + leaf::throw_exception( info<1>{1} ); }, []( info<1> const & x ) { @@ -132,7 +132,7 @@ int main() leaf::result r = leaf::try_handle_some( []() -> leaf::result { - throw leaf::exception( my_exception(), info<1>{1} ); + leaf::throw_exception( my_exception(), info<1>{1} ); }, error_handlers ); BOOST_TEST(r); @@ -142,7 +142,7 @@ int main() leaf::result r = leaf::try_handle_some( []() -> leaf::result { - throw leaf::exception( info<1>{1} ); + leaf::throw_exception( info<1>{1} ); }, error_handlers ); BOOST_TEST(r); @@ -178,7 +178,7 @@ int main() int r = leaf::try_handle_all( []() -> leaf::result { - throw leaf::exception( my_exception(), info<1>{1} ); + leaf::throw_exception( my_exception(), info<1>{1} ); }, []( my_exception const &, info<1> const & x ) { @@ -195,7 +195,7 @@ int main() int r = leaf::try_handle_all( []() -> leaf::result { - throw leaf::exception( info<1>{1} ); + leaf::throw_exception( info<1>{1} ); }, []( info<1> const & x ) { @@ -257,7 +257,7 @@ int main() int r = leaf::try_handle_all( []() -> leaf::result { - throw leaf::exception( my_exception(), info<1>{1} ); + leaf::throw_exception( my_exception(), info<1>{1} ); }, error_handlers ); BOOST_TEST_EQ(r, 1); @@ -266,7 +266,7 @@ int main() int r = leaf::try_handle_all( []() -> leaf::result { - throw leaf::exception( info<1>{1} ); + leaf::throw_exception( info<1>{1} ); }, error_handlers ); BOOST_TEST_EQ(r, 2); @@ -580,7 +580,7 @@ int main() leaf::result r = leaf::try_handle_some( []() -> leaf::result { - throw leaf::exception( my_exception(42) ); + leaf::throw_exception( my_exception(42) ); }, []( leaf::match_value m ) { @@ -606,7 +606,7 @@ int main() leaf::result r = leaf::try_handle_some( []() -> leaf::result { - throw leaf::exception( my_exception(42) ); + leaf::throw_exception( my_exception(42) ); }, []( leaf::match_value m ) { @@ -642,7 +642,7 @@ int main() int r = leaf::try_handle_all( []() -> leaf::result { - throw leaf::exception( my_exception(42) ); + leaf::throw_exception( my_exception(42) ); }, []( leaf::match_value m ) { @@ -674,7 +674,7 @@ int main() int r = leaf::try_handle_all( []() -> leaf::result { - throw leaf::exception( my_exception(42) ); + leaf::throw_exception( my_exception(42) ); }, []( leaf::match_value m ) { diff --git a/test/visibility_test_lib.cpp b/test/visibility_test_lib.cpp index 2c4a0ac..a94d303 100644 --- a/test/visibility_test_lib.cpp +++ b/test/visibility_test_lib.cpp @@ -21,7 +21,7 @@ leaf::result BOOST_SYMBOL_VISIBLE hidden_result() void BOOST_SYMBOL_VISIBLE hidden_throw() { auto load = leaf::on_error( my_info<1>{1}, my_info<3>{3} ); - throw leaf::exception( my_info<2>{2} ); + leaf::throw_exception( my_info<2>{2} ); } #endif