diff --git a/doc/leaf.adoc b/doc/leaf.adoc index e11c9bd1..9710dc04 100644 --- a/doc/leaf.adoc +++ b/doc/leaf.adoc @@ -1365,7 +1365,7 @@ return leaf::try_catch( [.text-right] <> | <> -NOTE: Follow this link to see a complete example program: https://github.com/boostorg/leaf/blob/master/example/try_capture_all_eh.cpp?ts=4[try_capture_all_eh.cpp]. +NOTE: Follow this link to see a complete example program: https://github.com/boostorg/leaf/blob/master/example/try_capture_all_exceptions.cpp?ts=4[try_capture_all_exceptions.cpp]. ''' @@ -1776,7 +1776,7 @@ int main() noexcept NOTE: Follow this link to see the complete program: https://github.com/boostorg/leaf/blob/master/example/lua_callback_result.cpp?ts=4[lua_callback_result.cpp]. -TIP: When using Lua with {CPP}, we need to protect the Lua interpreter from exceptions that may be thrown from {CPP} functions installed as `lua_CFunction` callbacks. Here is the program from this section rewritten to use a {CPP} exception (instead of `leaf::result`) to safely communicate errors out of the `do_work` function: https://github.com/boostorg/leaf/blob/master/example/lua_callback_eh.cpp?ts=4[lua_callback_eh.cpp]. +TIP: When using Lua with {CPP}, we need to protect the Lua interpreter from exceptions that may be thrown from {CPP} functions installed as `lua_CFunction` callbacks. Here is the program from this section rewritten to use a {CPP} exception (instead of `leaf::result`) to safely communicate errors out of the `do_work` function: https://github.com/boostorg/leaf/blob/master/example/lua_callback_exceptions.cpp?ts=4[lua_callback_exceptions.cpp]. '''' diff --git a/example/lua_callback_eh.cpp b/example/lua_callback_exceptions.cpp similarity index 100% rename from example/lua_callback_eh.cpp rename to example/lua_callback_exceptions.cpp diff --git a/example/print_file/print_file_eh.cpp b/example/print_file/print_file_exceptions.cpp similarity index 100% rename from example/print_file/print_file_eh.cpp rename to example/print_file/print_file_exceptions.cpp diff --git a/example/print_file/print_file_leaf_result.cpp b/example/print_file/print_file_leaf_result.cpp index bb9dd8fb..37834f9d 100644 --- a/example/print_file/print_file_leaf_result.cpp +++ b/example/print_file/print_file_leaf_result.cpp @@ -7,7 +7,7 @@ // It reads a text file in a buffer and prints it to std::cout, using LEAF to // handle errors. This version does not use exception handling. The version that -// does use exception handling is in print_file_eh.cpp. +// does use exception handling is in print_file_exceptions.cpp. #include diff --git a/example/print_file/print_file_system_result.cpp b/example/print_file/print_file_system_result.cpp index 9325ee03..b36ef09b 100644 --- a/example/print_file/print_file_system_result.cpp +++ b/example/print_file/print_file_system_result.cpp @@ -7,7 +7,7 @@ // It reads a text file in a buffer and prints it to std::cout, using LEAF to // handle errors. This version does not use exception handling. The version that -// does use exception handling is in print_file_eh.cpp. +// does use exception handling is in print_file_exceptions.cpp. #include diff --git a/example/print_file/readme.md b/example/print_file/readme.md index 76d52688..f9bba61b 100644 --- a/example/print_file/readme.md +++ b/example/print_file/readme.md @@ -15,5 +15,5 @@ different variation on error handling: * [print_file_outcome_result.cpp](./print_file_outcome_result.cpp) is the same as above, but using `boost::outcome::result` instead of `boost::leaf::result`. -* [print_file_eh.cpp](./print_file_eh.cpp) throws on error, using an error code +* [print_file_exceptions.cpp](./print_file_exceptions.cpp) throws on error, using an error code `enum` for classification of failures. diff --git a/example/readme.md b/example/readme.md index 323d9e4b..0109dce1 100644 --- a/example/readme.md +++ b/example/readme.md @@ -3,9 +3,9 @@ * [print_file](./print_file): The complete example from the [Five Minute Introduction](https://boostorg.github.io/leaf/#introduction). This directory contains several versions of the same program, each using a different error handling style. * [dynamic_capture_result.cpp](https://github.com/boostorg/leaf/blob/master/example/dynamic_capture_result.cpp?ts=4): Shows how to transport error objects between threads in a `leaf::result` object without using exception handling. -* [dynamic_capture_eh.cpp](https://github.com/boostorg/leaf/blob/master/example/dynamic_capture_eh.cpp?ts=4): Shows how to transport error objects between threads in an a `leaf::result` object using exception handling. +* [dynamic_capture_exceptions.cpp](https://github.com/boostorg/leaf/blob/master/example/dynamic_capture_exceptions.cpp?ts=4): Shows how to transport error objects between threads in an a `leaf::result` object using exception handling. * [lua_callback_result.cpp](https://github.com/boostorg/leaf/blob/master/example/lua_callback_result.cpp?ts=4): Transporting arbitrary error objects through an uncooperative C API. -* [lua_callback_eh.cpp](https://github.com/boostorg/leaf/blob/master/example/lua_callback_eh.cpp?ts=4): Transporting arbitrary error objects through an uncooperative exception-safe API. +* [lua_callback_exceptions.cpp](https://github.com/boostorg/leaf/blob/master/example/lua_callback_exceptions.cpp?ts=4): Transporting arbitrary error objects through an uncooperative exception-safe API. * [exception_to_result.cpp](https://github.com/boostorg/leaf/blob/master/example/exception_to_result.cpp?ts=4): Demonstrates how to transport exceptions through a `noexcept` layer in the program. * [exception_error_log.cpp](https://github.com/boostorg/leaf/blob/master/example/error_log.cpp?ts=4): Using `accumulate` to produce an error log. * [exception_error_trace.cpp](https://github.com/boostorg/leaf/blob/master/example/error_trace.cpp?ts=4): Same as above, but the log is recorded in a `std::deque` rather than just printed. diff --git a/example/try_capture_all_eh.cpp b/example/try_capture_all_exceptions.cpp similarity index 100% rename from example/try_capture_all_eh.cpp rename to example/try_capture_all_exceptions.cpp diff --git a/example/try_capture_all_result.cpp b/example/try_capture_all_result.cpp index 3165bdea..dda27778 100644 --- a/example/try_capture_all_result.cpp +++ b/example/try_capture_all_result.cpp @@ -3,7 +3,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // This is a simple program that demonstrates the use of LEAF to transport error -// objects between threads, without using exception handling. See capture_eh.cpp +// objects between threads, without using exception handling. See try_capture_all_exceptions.cpp // for the version that uses exception handling. #include diff --git a/meson.build b/meson.build index cf95bc96..c48a1f0d 100644 --- a/meson.build +++ b/meson.build @@ -238,51 +238,35 @@ endif if option_enable_examples - print_file_examples = [ - 'print_file_leaf_result' - ] + executable('print_file_leaf_result', 'example/print_file/print_file_leaf_result.cpp', dependencies: [leaf] ) if option_exceptions - print_file_examples += [ - 'print_file_eh' - ] + executable('print_file_exceptions', 'example/print_file/print_file_exceptions.cpp', dependencies: [leaf] ) endif if option_boost - print_file_examples += [ - 'print_file_system_result', - 'print_file_outcome_result' - ] + executable('print_file_system_result', 'example/print_file/print_file_system_result.cpp', dependencies: [leaf, dep_boost] ) + executable('print_file_outcome_result', 'example/print_file/print_file_outcome_result.cpp', dependencies: [leaf, dep_boost] ) endif - foreach e : print_file_examples - executable(e, 'example/print_file/'+e+'.cpp', dependencies: [leaf, dep_thread, dep_boost] ) - endforeach - -endif - -################################# - -if option_enable_examples - executable('error_log', 'example/error_log.cpp', dependencies: [leaf] ) executable('error_trace', 'example/error_trace.cpp', dependencies: [leaf] ) executable('print_half', 'example/print_half.cpp', dependencies: [leaf] ) - executable('try_capture_all_result', 'example/try_capture_all_result.cpp', dependencies: [leaf, dep_thread] ) - + executable('try_capture_all_result', 'example/try_capture_all_result.cpp', dependencies: [leaf] ) if option_exceptions + executable('try_capture_all_exceptions', 'example/try_capture_all_exceptions.cpp', dependencies: [leaf] ) executable('exception_to_result', 'example/exception_to_result.cpp', dependencies: [leaf] ) - executable('try_capture_all_eh', 'example/try_capture_all_eh.cpp', dependencies: [leaf, dep_thread] ) - if option_lua - executable('lua_callback_eh', 'example/lua_callback_eh.cpp', dependencies: [leaf, dep_lua] ) - endif - if option_boost - executable('asio_beast_leaf_rpc', 'example/asio_beast_leaf_rpc.cpp', dependencies: [leaf, dep_boost], override_options: ['cpp_std=c++17'] ) - endif endif if option_lua + if option_exceptions + executable('lua_callback_exceptions', 'example/lua_callback_exceptions.cpp', dependencies: [leaf, dep_lua] ) + endif executable('lua_callback_result', 'example/lua_callback_result.cpp', dependencies: [leaf, dep_lua] ) endif + if option_boost and option_exceptions + executable('asio_beast_leaf_rpc', 'example/asio_beast_leaf_rpc.cpp', dependencies: [leaf, dep_boost] ) + endif + endif ################################# @@ -294,7 +278,7 @@ if option_enable_benchmarks endif if option_exceptions - error('The option leaf_enable_benchmarks requires the built-in option cpp_eh set to none. Aborting.') + error('The option leaf_enable_benchmarks requires the built-in option cpp_exceptions set to none. Aborting.') endif dep_tl_expected = subproject('tl_expected').get_variable('headers') diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 39300cac..6285f74f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -152,12 +152,13 @@ compile-fail _compile-fail-result_2.cpp ; compile-fail _compile-fail-result_3.cpp ; compile-fail _compile-fail-result_4.cpp ; -exe try_capture_all_eh : ../example/try_capture_all_eh.cpp : single:no off:no leaf_debug_capture0:no leaf_release_capture0:no ; +exe try_capture_all_exceptions : ../example/try_capture_all_exceptions.cpp : single:no off:no leaf_debug_capture0:no leaf_release_capture0:no ; exe try_capture_all_result : ../example/try_capture_all_result.cpp : single:no leaf_debug_capture0:no leaf_release_capture0:no leaf_debug_embedded:no leaf_release_embedded:no ; -exe error_log : ../example/error_log.cpp : off:no ; -exe error_trace : ../example/error_trace.cpp : off:no ; +exe error_log : ../example/error_log.cpp ; +exe error_trace : ../example/error_trace.cpp ; exe exception_to_result : ../example/exception_to_result.cpp : off:no ; -exe print_file_eh : ../example/print_file/print_file_eh.cpp : off:no ; -exe print_file_leaf_result : ../example/print_file/print_file_leaf_result.cpp : off:no ; -exe print_file_system_result : ../example/print_file/print_file_system_result.cpp : off:no ; -exe print_half : ../example/print_half.cpp : off:no ; +exe print_file_exceptions : ../example/print_file/print_file_exceptions.cpp : off:no ; +exe print_file_leaf_result : ../example/print_file/print_file_leaf_result.cpp ; +exe print_file_outcome_result : ../example/print_file/print_file_outcome_result.cpp : 11:no 14:no leaf_debug_embedded:no leaf_release_embedded:no ; +exe print_file_system_result : ../example/print_file/print_file_system_result.cpp : 11:no 14:no leaf_debug_embedded:no leaf_release_embedded:no ; +exe print_half : ../example/print_half.cpp ; diff --git a/test/result_state_test.cpp b/test/result_state_test.cpp index f323a82c..15ca8c33 100644 --- a/test/result_state_test.cpp +++ b/test/result_state_test.cpp @@ -230,6 +230,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -246,6 +249,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -263,6 +269,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -285,6 +294,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -304,6 +316,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -323,6 +338,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -342,6 +360,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -361,6 +382,9 @@ int main() BOOST_TEST_EQ(err::count, 1); BOOST_TEST_EQ(val::count, 0); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -414,6 +438,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -430,6 +457,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -447,6 +477,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -465,6 +498,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -484,6 +520,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -502,6 +541,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2 = std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -520,6 +562,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -538,6 +583,9 @@ int main() BOOST_TEST(!r1.operator->()); BOOST_TEST_EQ(err::count, 1); leaf::error_id r1e = r1.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(std::error_code(r1e) == r1.error()); +#endif leaf::result r2; r2=std::move(r1); leaf::error_id r2e = r2.error(); BOOST_TEST_EQ(r1e, r2e); @@ -572,6 +620,9 @@ int main() BOOST_TEST_EQ(val::count, 0); BOOST_TEST(!r1); leaf::error_id id = r.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(!std::error_code(r.error())); +#endif BOOST_TEST(!id); } BOOST_TEST_EQ(val::count, 0); @@ -582,6 +633,9 @@ int main() leaf::result r1 = r.error(); BOOST_TEST(!r1); leaf::error_id id = r.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(!std::error_code(r.error())); +#endif BOOST_TEST(!id); BOOST_TEST_EQ(val::count, 1); } @@ -593,6 +647,9 @@ int main() leaf::result r1 = r.error(); BOOST_TEST(!r1); leaf::error_id id = r.error(); +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR + BOOST_TEST(!std::error_code(r.error())); +#endif BOOST_TEST(!id); BOOST_TEST_EQ(val::count, 1); }