Simple use case for boost exceptions

With boost::exception, can I simply construct an exception with a custom what() message (without subclassing exception)? Thanks. -- Yang Zhang http://www.mit.edu/~y_z/

On Thu, Dec 4, 2008 at 1:20 PM, Yang Zhang
With boost::exception, can I simply construct an exception with a custom what() message (without subclassing exception)? Thanks. -- Yang Zhang http://www.mit.edu/~y_z/
No, you can't. When throwing exceptions, you shouldn't be concerned with formatting a friendly user message, only with making sure that the exception contains enough information for such a message to be composed at the catch point. The primary boost::exception design goal is to streamline this process of transporting information to the catch point: see http://www.boost.org/doc/libs/1_37_0/libs/exception/doc/tutorial_transportin.... Also, instead of formatting a custom user-friendly message, you can use boost::diagnostic_information() to get a string that contains all the information carried by a boost::exception. See http://www.boost.org/doc/libs/1_37_0/libs/exception/doc/tutorial_diagnostic_.... Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (2)
-
Emil Dotchevski
-
Yang Zhang