|
1 | 1 |
|
2 | 2 | [#error_handling] |
3 | 3 |
|
4 | | -Errors can occur during `initialize`, or during method dispatch, if the |
5 | | -method's registry contains the `runtime_checks` policy. If the registry |
6 | | -contains an `error_handler` policy, its `error_handler::error` member |
7 | | -function is called with a variant containing an error object, before terminating |
8 | | -the program with a call to `abort`. `default_registry` contains such a |
9 | | -policy: `default_error_handler`. It wraps the error object in a variant, and |
10 | | -calls a handler via a `std::function`. By default, it prints a short description |
11 | | -of the error to `stderr`, but this can be changed, for example, to throw an |
12 | | -exception: |
| 4 | +Errors can occur during `initialize`, or during method dispatch, if the method's |
| 5 | +registry contains the `runtime_checks` policy. If the registry contains an |
| 6 | +`error_handler` policy, its `error_handler::error` member function is called |
| 7 | +with an error object, before terminating the program with a call to `abort`. |
| 8 | +`default_registry` contains such a policy: `default_error_handler`. It wraps the |
| 9 | +error object in a variant, and calls a handler via a `std::function`, |
| 10 | +initialized to a function that prints a short description of the error to |
| 11 | +`stderr`. The function can be changed, for example, to throw an exception: |
13 | 12 |
|
14 | 13 | [source,c++] |
15 | 14 | ---- |
|
43 | 42 |
|
44 | 43 | Stock policy `throw_error_handler` does this for all the error types: |
45 | 44 |
|
46 | | -```c++ namespace boost::openmethod::policies { |
| 45 | +```c++ |
| 46 | +namespace boost::openmethod::policies { |
47 | 47 |
|
48 | | -struct throw_error_handler : error_handler { template<class Error> |
49 | | - [[noreturn]] static auto error(const Error& error) -> void { throw |
50 | | - error; } |
| 48 | +struct throw_error_handler : error_handler { |
| 49 | + template<class Error> |
| 50 | + [[noreturn]] static auto error(const Error& error) -> void { |
| 51 | + throw error; |
| 52 | + } |
51 | 53 | }; |
52 | 54 |
|
53 | 55 | } // namespace boost::openmethod::policies |
|
0 commit comments