
On Tue, Oct 21, 2008 at 4:05 PM, Peng Yu <pengyu.ut@gmail.com> wrote:
Hi,
If there is an error happens, I want to throw an exception, with the error string of the following format (similar to what assert would give).
main.cc:12: int main(): some message
With Boost 1.37 (soon to be released), a new macro is introduced called BOOST_THROW_EXCEPTION. You use it like this: #include "boost/throw_exception.hpp" struct my_exception: std::exception { }; BOOST_THROW_EXCEPTION(my_exception()); It automatically records the throw location in the exception object. At the catch site, you can use boost::diagnostic_information to get a string that includes the throw location: #include "boost/exception/diagnostic_information.hpp" catch( my_exception & e ) { std::cerr << boost::diagnostic_information(e); } HTH, Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode