activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Lepage (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AMQCPP-373) AMQ_CATCH_RETHROW upcasts the re-thrown exception
Date Thu, 26 May 2011 13:31:47 GMT
AMQ_CATCH_RETHROW upcasts the re-thrown exception
-------------------------------------------------

                 Key: AMQCPP-373
                 URL: https://issues.apache.org/jira/browse/AMQCPP-373
             Project: ActiveMQ C++ Client
          Issue Type: Bug
          Components: CMS Impl, Decaf
    Affects Versions: 3.5.0
         Environment: Windows 7 (visual C++ 2005), Linux (gcc 4.1.2)
            Reporter: Martin Lepage
            Assignee: Timothy Bish
            Priority: Minor
         Attachments: exception.patch

AMQ_CATCH_RETHROW and DECAF_CATCH_RETHROW as defined in {{activemq/exceptions/ExceptionDefines.h}}
and {{decaf/lang/exceptions/ExceptionDefines.h}} upcast the exceptions when they rethrow it,
which results in loss of information (but not of data) along the way. 

Take for example the following c++ code fragment, which mimics the way AMQ_CATCH_RETHROW is
used throughout the code :

{code:title=Exception handling|borderStyle=solid}
#include <iostream>
#include <typeinfo>
#include <activemq/exceptions/ExceptionDefines.h>
#include <activemq/exceptions/BrokerException.h>

int main()
{
    try
    {
        try
        {
            try
            {
                throw activemq::exceptions::BrokerException(
                        __FILE__, __LINE__, "Testing");
            }
            AMQ_CATCH_RETHROW(activemq::exceptions::BrokerException)
        }
        AMQ_CATCH_RETHROW(activemq::exceptions::ActiveMQException)
    }
    catch (decaf::lang::Throwable &e)
    {
        std::cout.flags(std::ios_base::boolalpha);

        std::cout << "Broker exception : " << (typeid(e).name() == 
                typeid(activemq::exceptions::BrokerException).name()) << "\n";

        std::cout << "ActiveMQException : " << (typeid(e).name() == 
                typeid(activemq::exceptions::ActiveMQException).name()) << "\n";
        
        decaf::lang::Throwable *convertedException =
            dynamic_cast<activemq::exceptions::BrokerException *>(&e);

        std::cout << "Conversion failed : " << (convertedException == NULL)
                  << "\n";
    }
    return 0;
}
{code} 

which returns :

{code:xml} 
Broker exception : false
ActiveMQException : true
Conversion failed : true
{code} 

The solution is to replace '{{throw e;}}' by '{{throw;}}' in the definitions of AMQ_CATCH_RETHROW
and DECAF_CATCH_RETHROW.



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message