Boost logo

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).
> 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 { };


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);

Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at