You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by ol...@cantor.fr on 2007/06/25 16:08:30 UTC

making ExceptionListener#onException behave based on Exception type

Hello

I'm using ActiveMQ-CPP 2.0.1. In my program, I want to handle exceptions thrown
by a Connection object, through its ExceptionListener, and act differently
depending on the type of exception that occured.

So, I set my implementation of ExceptionListener for the Connection, so that
my implementation of onException(CMSException) method is called whenever an
error occurs. Inside this method, I can get the stack trace, and the message
from the CMSException object. But I cannot get its type (IOException,
IllegalStateException, etc...).

To behave differently depending on the Exception type, I tried the following :

- Implementing multiple ExceptionListener#onException taking different types of
exceptions doesn't work.
- Throwing the exception and catching again is not possible, since CMSException
is abstract.
- Using typeid() to find the type requires RTTI to be enabled. Using typeid does
not seems to be a good design, and it is not recommended in the company I work.
- Parsing the error message is a last ressort.

Is there another solution I missed ?

Re: making ExceptionListener#onException behave based on Exception type

Posted by ol...@cantor.fr.
Selon Timothy Bish <ta...@twcny.rr.com>:

> olivier.renaud@cantor.fr wrote:
> > Timothy Bish <ta...@twcny.rr.com>:
> >
> >
> >> Have you tried casting the CMSException to the various types that you
> >> want to handle?
> >>
> >
> > You mean, using a dynamic_cast ? dynamic_cast needs RTTI too, I think, so
> the
> > problem is the same than using typeid.
> >
> >
>
> Not sure what your trepidation is in using RTTI, AMQCPP wouldn't be able
> to work without it, its a pretty standard tool set in C++ at this
> point.  I don't know what to tell you if you can't use RTTI.
>

The worry about rtti is a compatibility problem : as our whole project is not
compiled with rtti, and as I thought it could lead to binary compatibility
problem, I wanted to avoid it. But it's true that ActiveMQ-CPP (which uses it)
and my code (which does not) work together without problem, so it may be safe.

Thanks for your responses.



Re: making ExceptionListener#onException behave based on Exception type

Posted by Timothy Bish <ta...@twcny.rr.com>.
olivier.renaud@cantor.fr wrote:
> Timothy Bish <ta...@twcny.rr.com>:
>
>   
>> Have you tried casting the CMSException to the various types that you
>> want to handle?
>>     
>
> You mean, using a dynamic_cast ? dynamic_cast needs RTTI too, I think, so the
> problem is the same than using typeid.
>
>   

Not sure what your trepidation is in using RTTI, AMQCPP wouldn't be able 
to work without it, its a pretty standard tool set in C++ at this 
point.  I don't know what to tell you if you can't use RTTI.

Re: making ExceptionListener#onException behave based on Exception type

Posted by ol...@cantor.fr.
Timothy Bish <ta...@twcny.rr.com>:

> Have you tried casting the CMSException to the various types that you
> want to handle?

You mean, using a dynamic_cast ? dynamic_cast needs RTTI too, I think, so the
problem is the same than using typeid.

Re: making ExceptionListener#onException behave based on Exception type

Posted by Timothy Bish <ta...@twcny.rr.com>.
Have you tried casting the CMSException to the various types that you 
want to handle?

olivier.renaud@cantor.fr wrote:
> Hello
>
> I'm using ActiveMQ-CPP 2.0.1. In my program, I want to handle exceptions thrown
> by a Connection object, through its ExceptionListener, and act differently
> depending on the type of exception that occured.
>
> So, I set my implementation of ExceptionListener for the Connection, so that
> my implementation of onException(CMSException) method is called whenever an
> error occurs. Inside this method, I can get the stack trace, and the message
> from the CMSException object. But I cannot get its type (IOException,
> IllegalStateException, etc...).
>
> To behave differently depending on the Exception type, I tried the following :
>
> - Implementing multiple ExceptionListener#onException taking different types of
> exceptions doesn't work.
> - Throwing the exception and catching again is not possible, since CMSException
> is abstract.
> - Using typeid() to find the type requires RTTI to be enabled. Using typeid does
> not seems to be a good design, and it is not recommended in the company I work.
> - Parsing the error message is a last ressort.
>
> Is there another solution I missed ?
>
>