Skip to content

Commit e64865a

Browse files
committed
Sync from upstream.
2 parents b591cbd + 7bd20a5 commit e64865a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

doc/leaf.adoc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ Besides error objects, `load` can take function arguments:
861861

862862
* If we pass a function that takes no arguments, it is invoked, and the returned error object is loaded.
863863
+
864-
Consider that if we pass to `load` an error object that is not used by an error handler, it will be discarded. If the object is expensive to compute, it would be better if the computation is only performed in case of an error. Passing a function with no arguments to `load` is an excellent way to achieve this behavior:
864+
Consider that if we pass to `load` an error object that is not used by an error handler, it will be discarded. If instead of an error object we pass a function that returns an error object, that function will only be called if the object it returns is needed, that is, if it will not be discarded. This is helpful when the error object is relatively expensive to produce:
865865
+
866866
[source,c++]
867867
----
@@ -968,7 +968,7 @@ When we invoke `on_error`, we can pass three kinds of arguments:
968968
. Functions that take no arguments and return an error object;
969969
. Functions that take a single error object by mutable reference.
970970

971-
For example, if we want to use `on_error` to capture `errno`, we can't just pass <<e_errno>> to it, because at that time it hasn't been set (yet). Instead, we'd pass a function that returns it:
971+
For example, if we want to use `on_error` to capture `errno`, we could use the <<e_errno>> type, which is a simple struct that wraps an `int`. But, we can't just pass an <<e_errno>> to `on_error`, because at that time `errno` hasn't been set (yet). Instead, we'd pass a function that returns it:
972972

973973
[source,c++]
974974
----
@@ -1821,12 +1821,15 @@ The `diagnostic_details` output for the snippet above tells us that we got an `e
18211821

18221822
----
18231823
Unrecognized error detected
1824-
Error serial #1
1825-
Diagnostic details:
1824+
Error with serial #1
1825+
Caught:
18261826
error_code: 1
1827+
Diagnostic details:
18271828
boost::leaf::e_file_name: file.txt
18281829
----
18291830

1831+
TIP: In the `diagnostic_details` output, the section under `Caught:` lists the objects which error handlers take as arguments -- these are the objects which are stored on the stack. The section under `Diagnostic details:` lists all other objects that were communicated. These are the objects that would have been discarded if we didn't provide a handler that takes `diagnostic_details`.
1832+
18301833
To print each error object, LEAF attempts to bind an unqualified call to `operator<<`, passing a `std::ostream` and the error object. If that fails, it will also attempt to bind `operator<<` that takes the `.value` of the error type. If that also does not compile, the error object value will not appear in diagnostic messages, though LEAF will still print its type.
18311834

18321835
Even with error types that define a printable `.value`, the user may still want to overload `operator<<` for the enclosing `struct`, e.g.:
@@ -1839,7 +1842,7 @@ struct e_errno
18391842
18401843
friend std::ostream & operator<<( std::ostream & os, e_errno const & e )
18411844
{
1842-
return os << "errno = " << e.value << ", \"" << strerror(e.value) << '"';
1845+
return os << e.value << ", \"" << strerror(e.value) << '"';
18431846
}
18441847
};
18451848
----
@@ -1880,9 +1883,9 @@ Caught:
18801883
error_code: 1
18811884
----
18821885

1883-
Notice how the diagnostic information for `e_file_name` changed: because it was discarded, LEAF is unable to print it.
1886+
Notice how we are missing the `Diagnostic details:` section. That's because the `e_file_name` object was discarded by LEAF, since no error handler needed it.
18841887

1885-
TIP: The automatically-generated diagnostic messages are developer-friendly, but not user-friendly. Therefore, `operator<<` overloads for error types should only print technical information in English, and should not attempt to localize strings or to format a user-friendly message; this should be done in error handling functions specifically designed for that purpose.
1888+
TIP: The automatically-generated diagnostic messages are developer-friendly, but not user-friendly.
18861889

18871890
'''
18881891

0 commit comments

Comments
 (0)