Reporting non-fatal errors in Boost libraries

Most of the time when a library routine encounters an error, that error is fatal, and the proper course of action is fairly obvious: throw an exception, return a singular value, or similar. However, in some cases, we encounter errors that are non-fatal, and simply giving up is not the most appropriate course of action. The error encountered may be inconsequential to successful completion, or we may have gotten notification of the error too late for it to make a difference, or design considerations may prevent us from terminating. A common example is encountering an unrecoverable error in a destructor while closing a file. These errors must be reported. However, without making special provisions for doing so, its unclear exactly how to report them. As we're in code for generic libraries, suggestions such as printing to std::cerr are clearly unacceptable. We also want to avoid encumbering the library interface with error-handling clutter that may never be used. How should Boost libraries be designed so as to allow these errors to be reported? Do existing Boost libraries have problems with these situations, and if so, how have they solved it? Aaron W. LaFramboise

David Abrahams wrote:
"Robert Ramey" <ramey@rrsd.com> writes:
Consider boost::static_warning
As that is not in the detail namespace/directory it must be documented somewhere... where is that?
It's in the index of the saerialization library, but the entry just says "to do." (Since Robert isn't using my javascript menu component I can't post a link to it.) It's been about a year since I emailed Robert Ramey some changes to static warning to make it work on more compilers. I subsequently discovered that none of the versions worked very well with templates (the main use case), and came up with an improved implementation that worked just about everywhere except some intermediate versions of GCC. When I have a chance I will try to find my improved version and commit it. I'll also write some documentation. Jonathan

"Aaron W. LaFramboise" <aaronrabiddog51@aaronwl.com> writes:
Most of the time when a library routine encounters an error, that error is fatal, and the proper course of action is fairly obvious: throw an exception, return a singular value, or similar.
However, in some cases, we encounter errors that are non-fatal, and simply giving up is not the most appropriate course of action. The error encountered may be inconsequential to successful completion, or we may have gotten notification of the error too late for it to make a difference, or design considerations may prevent us from terminating. A common example is encountering an unrecoverable error in a destructor while closing a file.
These errors must be reported. However, without making special provisions for doing so, its unclear exactly how to report them. As we're in code for generic libraries, suggestions such as printing to std::cerr are clearly unacceptable. We also want to avoid encumbering the library interface with error-handling clutter that may never be used.
How should Boost libraries be designed so as to allow these errors to be reported? Do existing Boost libraries have problems with these situations, and if so, how have they solved it?
You might try instantiating boost::mpl::print<Some_Type_Whose_Name_Describes_The_Problem> -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (4)
-
Aaron W. LaFramboise
-
David Abrahams
-
Jonathan Turkanis
-
Robert Ramey