diff --git a/error_handling.html b/error_handling.html index d804ecb..14035f4 100644 --- a/error_handling.html +++ b/error_handling.html @@ -94,16 +94,31 @@ throw some_exception(); that you have a fallback in case the formatting code throws
what()
- message. It's nice to have a message that a programmer stands a
- chance of figuring out, but you're very unlikely to be able to compose
- a relevant and user-comprehensible error message at the point an
- exception is thrown. Certainly, internationalization is beyond the
- scope of the exception class author. Peter Dimov makes an excellent argument
- that the proper use of a what()
string is to serve as a
- key into a table of error messages. Now if only we could get
- standardized what()
strings for exceptions thrown by the
- standard library...what()
string is
+ to serve as a key into a table of error message formatters. Now
+ if only we could get standardized what()
strings
+ for exceptions thrown by the standard library...
+
+ what()
message is likely to mean that you
+ neglect to expose information someone might need in order to
+ make a coherent message for users. For example, if your
+ exception reports a numeric range error, it's important to have
+ the actual numbers involved available as numbers in the
+ exception class' public interface where error reporting code can
+ do something intelligent with them. If you only expose a
+ textual representation of those numbers in
+ the what()
string, you will make life very
+ difficult for programmers who need to do something more
+ (e.g. subtraction) with them than dumb output.