You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/02/05 16:25:37 UTC

svn commit: r741133 - in /activemq/activemq-cpp/trunk/src: main/cms/CMSException.h main/decaf/lang/Throwable.h test/activemq/exceptions/ActiveMQExceptionTest.cpp test/testRegistry.cpp

Author: tabish
Date: Thu Feb  5 15:25:37 2009
New Revision: 741133

URL: http://svn.apache.org/viewvc?rev=741133&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-218

Make std::exception the virtual base class of the exception types so that ActiveMQException can be a Decaf Exception and a CMSException and still be automatically converted to std::exception in the catch clause.

Modified:
    activemq/activemq-cpp/trunk/src/main/cms/CMSException.h
    activemq/activemq-cpp/trunk/src/main/decaf/lang/Throwable.h
    activemq/activemq-cpp/trunk/src/test/activemq/exceptions/ActiveMQExceptionTest.cpp
    activemq/activemq-cpp/trunk/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/src/main/cms/CMSException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/cms/CMSException.h?rev=741133&r1=741132&r2=741133&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/cms/CMSException.h (original)
+++ activemq/activemq-cpp/trunk/src/main/cms/CMSException.h Thu Feb  5 15:25:37 2009
@@ -32,7 +32,7 @@
      * This class represents an error that has occurred in
      * cms.
      */
-    class CMS_API CMSException : public std::exception {
+    class CMS_API CMSException : public virtual std::exception {
 
     public:
 

Modified: activemq/activemq-cpp/trunk/src/main/decaf/lang/Throwable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Throwable.h?rev=741133&r1=741132&r2=741133&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Throwable.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Throwable.h Thu Feb  5 15:25:37 2009
@@ -32,7 +32,7 @@
     /**
      * This class represents an error that has occurred.
      */
-    class DECAF_API Throwable : public std::exception {
+    class DECAF_API Throwable : public virtual std::exception {
     public:
 
         Throwable() throw() {}

Modified: activemq/activemq-cpp/trunk/src/test/activemq/exceptions/ActiveMQExceptionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/exceptions/ActiveMQExceptionTest.cpp?rev=741133&r1=741132&r2=741133&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/exceptions/ActiveMQExceptionTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/exceptions/ActiveMQExceptionTest.cpp Thu Feb  5 15:25:37 2009
@@ -49,6 +49,38 @@
 
         CPPUNIT_ASSERT( cause != NULL );
     }
+
+    try{
+        throw ActiveMQException( __FILE__, __LINE__, "TEST" );
+    } catch( std::exception& ex ) {
+        return;
+    }
+
+    CPPUNIT_FAIL( "Should have returned after catching an std exception." );
+
+    try{
+
+        try{
+            try{
+                throw UnsupportedOperationException( __FILE__, __LINE__, "EXCEPTION" );
+                CPPUNIT_FAIL( "Should not get this far." );
+            }
+            AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
+        }
+        AMQ_CATCH_RETHROW( ActiveMQException )
+
+    } catch( std::exception& ex ) {
+
+        ActiveMQException* converted = dynamic_cast<ActiveMQException*>( &ex );
+
+        CPPUNIT_ASSERT( converted != NULL );
+        CPPUNIT_ASSERT( converted->getCause() != NULL );
+
+        const UnsupportedOperationException* cause =
+            dynamic_cast<const UnsupportedOperationException*>( converted->getCause() );
+
+        CPPUNIT_ASSERT( cause != NULL );
+    }
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/testRegistry.cpp?rev=741133&r1=741132&r2=741133&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/testRegistry.cpp Thu Feb  5 15:25:37 2009
@@ -86,10 +86,10 @@
 //CPPUNIT_TEST_SUITE_REGISTRATION( activemq::transport::TransportRegistryTest );
 //#include <activemq/transport/IOTransportTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( activemq::transport::IOTransportTest );
-//
-//#include <activemq/exceptions/ActiveMQExceptionTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( activemq::exceptions::ActiveMQExceptionTest );
-//
+
+#include <activemq/exceptions/ActiveMQExceptionTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::exceptions::ActiveMQExceptionTest );
+
 //#include <activemq/util/LongSequenceGeneratorTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( activemq::util::LongSequenceGeneratorTest );
 //#include <activemq/util/PrimitiveValueNodeTest.h>