Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-14 12:32:53


"Rozental, Gennadiy" <gennadiy.rozental_at_[hidden]> writes:

>> I've encountered a problem with exceptions in boost/test:
>> Our project uses a base class for all our exceptions which
>> cannot derive
>> from std::exception.
>>
>> If such an exception is thrown, the message:
>> Exception in "...": unknown type
>> is printed out, which is not very helpful in locating the problem.
>>
>> Is there a way to specify an "exception handler", which can
>> catch "our"
>> exceptions and print something more useful?.
>
> I could do something along following lines:
>
> #include <iostream>
> using namespace std;
>
> void
> unknown_exception_handler()
> {
> try {
> throw;
> }
> catch( int i ) {
> cout << "int caught\n";
> }
> }
>
>
> int main()
> {
> try {
> throw 1;
> }
> catch( ... ) {
> try {
> unknown_exception_handler();
> } catch( ... ) {
> cout << "unknown exception\n";
> }
> }
> }
>
> and provide a way to configure unknown_exception_handler.
> Dave, do you have something different in mind?

Yes; check out
http://www.boost.org/libs/python/doc/v2/exception_translator.html

This allows multiple independently registered exception handlers.
Whether or not that's overkill for your purposes is another matter.

note however that the try { throw; } idiom breaks on many popular
compilers that are still in use, which is why my code doesn't use it.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk