|
Boost : |
Subject: Re: [boost] Are there any some utilities that helps to show where a exception is from?
From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-10-21 23:56:01
On Tue, Oct 21, 2008 at 4:05 PM, Peng Yu <pengyu.ut_at_[hidden]> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk