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 2012/10/12 22:18:20 UTC

svn commit: r1397715 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/commands/ main/activemq/core/ main/activemq/exceptions/ main/decaf/lang/ main/decaf/lang/exceptions/ main/decaf/util/concurrent/ main/decaf/util/zip/ test/decaf/lang/

Author: tabish
Date: Fri Oct 12 20:18:19 2012
New Revision: 1397715

URL: http://svn.apache.org/viewvc?rev=1397715&view=rev
Log:
Allow the brokers Exceptions responses to turn into the appropriate cms::CMSException types which are thrown

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/ExceptionDefines.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/FutureTask.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ExceptionTest.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.cpp Fri Oct 12 20:18:19 2012
@@ -18,11 +18,29 @@
 #include <activemq/state/CommandVisitor.h>
 #include <activemq/exceptions/ActiveMQException.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/util/StringTokenizer.h>
+#include <string>
+
+#include <cms/CMSException.h>
+#include <cms/CMSSecurityException.h>
+#include <cms/MessageEOFException.h>
+#include <cms/MessageFormatException.h>
+#include <cms/MessageNotReadableException.h>
+#include <cms/MessageNotWriteableException.h>
+#include <cms/InvalidClientIdException.h>
+#include <cms/InvalidDestinationException.h>
+#include <cms/InvalidSelectorException.h>
+#include <cms/IllegalStateException.h>
+#include <cms/ResourceAllocationException.h>
+#include <cms/TransactionInProgressException.h>
+#include <cms/TransactionRolledBackException.h>
+#include <cms/UnsupportedOperationException.h>
 
 using namespace std;
 using namespace activemq;
 using namespace activemq::exceptions;
 using namespace activemq::commands;
+using namespace decaf::util;
 using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
@@ -36,9 +54,9 @@ BrokerError::~BrokerError() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void BrokerError::copyDataStructure( const DataStructure* src ) {
+void BrokerError::copyDataStructure(const DataStructure* src) {
 
-    const BrokerError* srcErr = dynamic_cast<const BrokerError*> (src);
+    const BrokerError* srcErr = dynamic_cast<const BrokerError*>(src);
 
     if (srcErr == NULL || src == NULL) {
         throw NullPointerException(__FILE__, __LINE__, "BrokerError::copyCommand - src is NULL or invalid");
@@ -51,15 +69,56 @@ void BrokerError::copyDataStructure( con
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Pointer<commands::Command> BrokerError::visit( activemq::state::CommandVisitor* visitor ) {
+Pointer<commands::Command> BrokerError::visit(activemq::state::CommandVisitor* visitor) {
     return visitor->processBrokerError(this);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 decaf::lang::Exception BrokerError::createExceptionObject() {
 
-    // TODO Would be nice to actually create an exception matching the broker reported
-    // type as well as preserving the supplied stack trace and possible embedded cause.
-    Exception theCause(__FILE__, __LINE__, this->getMessage().c_str());
+    StringTokenizer tokenizer(this->exceptionClass);
+    std::string exceptionClass = this->exceptionClass;
+
+    while (tokenizer.hasMoreTokens()) {
+        exceptionClass = tokenizer.nextToken();
+    }
+
+    cms::CMSException* cause = NULL;
+
+    if (exceptionClass == "JMSException") {
+        cause = new cms::CMSException(this->message);
+    } else if (exceptionClass == "JMSSecurityException") {
+        cause = new cms::CMSSecurityException(this->message);
+    } else if (exceptionClass == "MessageEOFException") {
+        cause = new cms::MessageEOFException(this->message);
+    } else if (exceptionClass == "MessageFormatException") {
+        cause = new cms::MessageFormatException(this->message);
+    } else if (exceptionClass == "MessageNotReadableException") {
+        cause = new cms::MessageNotReadableException(this->message);
+    } else if (exceptionClass == "MessageNotWriteableException") {
+        cause = new cms::MessageNotWriteableException(this->message);
+    } else if (exceptionClass == "InvalidClientIdException") {
+        cause = new cms::InvalidClientIdException(this->message);
+    } else if (exceptionClass == "InvalidDestinationException") {
+        cause = new cms::InvalidDestinationException(this->message);
+    } else if (exceptionClass == "InvalidSelectorException") {
+        cause = new cms::InvalidSelectorException(this->message);
+    } else if (exceptionClass == "IllegalStateException") {
+        cause = new cms::IllegalStateException(this->message);
+    } else if (exceptionClass == "ResourceAllocationException") {
+        cause = new cms::ResourceAllocationException(this->message);
+    } else if (exceptionClass == "TransactionInProgressException") {
+        cause = new cms::TransactionInProgressException(this->message);
+    } else if (exceptionClass == "TransactionRolledBackException") {
+        cause = new cms::TransactionRolledBackException(this->message);
+    } else if (exceptionClass == "UnsupportedOperationException") {
+        cause = new cms::UnsupportedOperationException(this->message);
+    } else {
+        cause = new cms::CMSException(this->message);
+    }
+
+    // Wrap in a Decaf exception to carry the pointer until it can be
+    // thrown in a context that will convey the correct type to the client.
+    Exception theCause(__FILE__, __LINE__, cause, this->getMessage().c_str());
     return theCause;
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/BrokerError.h Fri Oct 12 20:18:19 2012
@@ -162,6 +162,9 @@ namespace commands {
         /**
          * Creates and returns a Decaf Exception object that contains the error data from the Broker.
          *
+         * The returned exception will if possible contain a cms::CMSException pointer that represents
+         * the actual JMS exception that was forwarded from the broker.
+         *
          * @return a new instance of a Decaf Exception
          */
         decaf::lang::Exception createExceptionObject();

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp Fri Oct 12 20:18:19 2012
@@ -307,8 +307,14 @@ namespace core{
             try {
                 cms::ExceptionListener* listener = this->connection->getExceptionListener();
                 if (listener != NULL) {
-                    ActiveMQException amqEx(ex);
-                    listener->onException(amqEx.convertToCMSException());
+
+                    const cms::CMSException* cause = dynamic_cast<const cms::CMSException*>(ex.getCause());
+                    if (cause != NULL) {
+                        listener->onException(*cause);
+                    } else {
+                        ActiveMQException amqEx(ex);
+                        listener->onException(amqEx.convertToCMSException());
+                    }
                 }
             } catch(Exception& ex) {}
         }
@@ -1178,21 +1184,22 @@ Pointer<Response> ActiveMQConnection::sy
 
         if (exceptionResponse != NULL) {
 
-            // Create an exception to hold the error information.
-            BrokerException exception(__FILE__, __LINE__, exceptionResponse->getException().get());
+            Exception ex = exceptionResponse->getException()->createExceptionObject();
+            if (ex.getCause() != NULL) {
+                throw *(ex.getCause());
+            }
 
-            // Throw the exception.
-            throw exception;
+            throw BrokerException(__FILE__, __LINE__, exceptionResponse->getException()->getMessage().c_str());
         }
 
         return response;
     }
-    AMQ_CATCH_RETHROW( cms::CMSException )
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCH_EXCEPTION_CONVERT( IOException, ActiveMQException )
-    AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::exceptions::UnsupportedOperationException, ActiveMQException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    AMQ_CATCH_RETHROW(cms::CMSException)
+    AMQ_CATCH_RETHROW(ActiveMQException)
+    AMQ_CATCH_EXCEPTION_CONVERT(IOException, ActiveMQException)
+    AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::exceptions::UnsupportedOperationException, ActiveMQException)
+    AMQ_CATCH_EXCEPTION_CONVERT(Exception, ActiveMQException)
+    AMQ_CATCHALL_THROW(ActiveMQException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp Fri Oct 12 20:18:19 2012
@@ -25,7 +25,7 @@ using namespace std;
 
 // For supporting older versions of msvc (<=2003)
 #if defined(_MSC_VER) && (_MSC_VER < 1400)
-    #define vsnprintf _vsnprintf
+#define vsnprintf _vsnprintf
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -33,43 +33,31 @@ ActiveMQException::ActiveMQException() :
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQException::ActiveMQException( const ActiveMQException& ex )
-: decaf::lang::Exception() {
-
-  this->message = ex.getMessage();
-  this->stackTrace = ex.getStackTrace();
-  this->initCause( ex.cause );
+ActiveMQException::ActiveMQException(const ActiveMQException& ex) : decaf::lang::Exception(ex) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQException::ActiveMQException( const Exception& ex )
-: decaf::lang::Exception() {
-
-  this->message = ex.getMessage();
-  this->stackTrace = ex.getStackTrace();
-  this->initCause( &ex );
+ActiveMQException::ActiveMQException(const Exception& ex) : decaf::lang::Exception(ex.clone()) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQException::ActiveMQException( const char* file, const int lineNumber,
-                                      const char* msg, ... )
-: decaf::lang::Exception() {
+ActiveMQException::ActiveMQException(const char* file, const int lineNumber, const char* msg, ...) : decaf::lang::Exception() {
 
     va_list vargs;
-    va_start( vargs, msg ) ;
-    buildMessage( msg, vargs );
+    va_start(vargs, msg);
+    buildMessage(msg, vargs);
 
     // Set the first mark for this exception.
-    Exception::setMark( file, lineNumber );
+    Exception::setMark(file, lineNumber);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQException::~ActiveMQException() throw() {
+ActiveMQException::~ActiveMQException() throw () {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQException* ActiveMQException::clone() const{
-    return new ActiveMQException( *this );
+ActiveMQException* ActiveMQException::clone() const {
+    return new ActiveMQException(*this);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -77,15 +65,15 @@ cms::CMSException ActiveMQException::con
 
     std::exception* result = NULL;
 
-    if( this->getCause() != NULL ) {
-        const Exception* ptrCause = dynamic_cast<const Exception*>( this->getCause() );
+    if (this->getCause() != NULL) {
+        const Exception* ptrCause = dynamic_cast<const Exception*>(this->getCause());
 
-        if( ptrCause == NULL ) {
-            result = new Exception( __FILE__, __LINE__, cause->what() );
+        if (ptrCause == NULL) {
+            result = new Exception(__FILE__, __LINE__, getCause()->what());
         } else {
             result = ptrCause->clone();
         }
     }
 
-    return cms::CMSException( this->getMessage(), result, this->getStackTrace() );
+    return cms::CMSException(this->getMessage(), result, this->getStackTrace());
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.h?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.h Fri Oct 12 20:18:19 2012
@@ -48,7 +48,7 @@ namespace exceptions{
          * @param ex
          *      The Exception whose internal data is copied into this instance.
          */
-        ActiveMQException( const ActiveMQException& ex );
+        ActiveMQException(const ActiveMQException& ex);
 
         /**
          * Copy Constructor
@@ -56,7 +56,7 @@ namespace exceptions{
          * @param ex
          *      The Exception whose internal data is copied into this instance.
          */
-        ActiveMQException( const decaf::lang::Exception& ex );
+        ActiveMQException(const decaf::lang::Exception& ex);
 
         /**
          * Constructor - Initializes the file name and line number where

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp Fri Oct 12 20:18:19 2012
@@ -18,6 +18,7 @@
 #include "Exception.h"
 #include <decaf/util/logging/LoggerDefines.h>
 #include <decaf/internal/AprPool.h>
+#include <decaf/lang/Pointer.h>
 
 #include <sstream>
 #include <apr_strings.h>
@@ -28,112 +29,132 @@ using namespace decaf::internal;
 using namespace decaf::lang;
 using namespace decaf::util::logging;
 
+namespace decaf {
+namespace lang {
+
+    class ExceptionData {
+    public:
+
+        /**
+         * The cause of this exception.
+         */
+        std::string message;
+
+        /**
+         * The Exception that caused this one to be thrown.
+         */
+        decaf::lang::Pointer<const std::exception> cause;
+
+        /**
+         * The stack trace.
+         */
+        std::vector< std::pair< std::string, int> > stackTrace;
+
+    public:
+
+        ExceptionData() : message(), cause(NULL), stackTrace() {}
+
+    };
+
+}}
+
 ////////////////////////////////////////////////////////////////////////////////
-Exception::Exception() : Throwable(), message(), cause(NULL), stackTrace() {
+Exception::Exception() : Throwable(), data(new ExceptionData) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Exception::Exception( const Exception& ex ) : Throwable(), message(), cause(NULL), stackTrace() {
+Exception::Exception(const Exception& ex) : Throwable(), data(new ExceptionData) {
     *this = ex;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Exception::Exception( const std::exception* cause ) : Throwable(), message(), cause(NULL), stackTrace() {
-    this->initCause( cause );
+Exception::Exception(const std::exception* cause) : Throwable(), data(new ExceptionData) {
+    this->initCause(cause);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Exception::Exception( const char* file, const int lineNumber,
-                      const char* msg, ... ) : Throwable(), message(), cause(NULL), stackTrace() {
+Exception::Exception(const char* file, const int lineNumber, const char* msg, ...) :
+    Throwable(), data(new ExceptionData) {
+
     va_list vargs;
-    va_start( vargs, msg ) ;
-    buildMessage( msg, vargs );
-    va_end( vargs );
+    va_start(vargs, msg);
+    buildMessage(msg, vargs);
+    va_end(vargs);
 
     // Set the first mark for this exception.
-    setMark( file, lineNumber );
+    setMark(file, lineNumber);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Exception::Exception( const char* file, const int lineNumber,
-                      const std::exception* cause,
-                      const char* msg, ... ) : Throwable(), message(), cause(NULL), stackTrace() {
+Exception::Exception(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...) :
+    Throwable(), data(new ExceptionData) {
+
     va_list vargs;
-    va_start( vargs, msg ) ;
-    this->buildMessage( msg, vargs );
-    va_end( vargs );
+    va_start(vargs, msg);
+    this->buildMessage(msg, vargs);
+    va_end(vargs);
 
     // Store the cause
-    this->initCause( cause );
+    this->initCause(cause);
 
     // Set the first mark for this exception.
-    this->setMark( file, lineNumber );
+    this->setMark(file, lineNumber);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Exception::~Exception() throw(){
-    delete this->cause;
+Exception::~Exception() throw () {
+    delete this->data;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Exception::setMessage( const char* msg, ... ){
+void Exception::setMessage(const char* msg, ...) {
     va_list vargs;
-    va_start( vargs, msg );
-    buildMessage( msg, vargs );
-    va_end( vargs );
+    va_start(vargs, msg);
+    buildMessage(msg, vargs);
+    va_end(vargs);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Exception::buildMessage( const char* format, va_list& vargs ) {
+void Exception::buildMessage(const char* format, va_list& vargs) {
 
     // Allocate buffer with a guess of it's size
     AprPool pool;
 
     // Allocate a buffer of the specified size.
-    char* buffer = apr_pvsprintf( pool.getAprPool(), format, vargs );
+    char* buffer = apr_pvsprintf(pool.getAprPool(), format, vargs);
 
     // Guessed size was enough. Assign the string.
-    message.assign( buffer, strlen( buffer ) );
+    this->data->message.assign(buffer, strlen(buffer));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Exception::setMark( const char* file, const int lineNumber ) {
-
+void Exception::setMark(const char* file, const int lineNumber) {
     // Add this mark to the end of the stack trace.
-    stackTrace.push_back( std::make_pair( std::string( file ), (int)lineNumber ) );
-
-    //std::ostringstream stream;
-    //stream << "\tFILE: " << stackTrace[stackTrace.size()-1].first;
-    //stream << ", LINE: " << stackTrace[stackTrace.size()-1].second;
-
-    //decaf::util::logger::SimpleLogger logger("com.yadda2");
-    //logger.log( stream.str() );
+    this->data->stackTrace.push_back(std::make_pair(std::string(file), (int) lineNumber));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 Exception* Exception::clone() const {
-    return new Exception( *this );
+    return new Exception(*this);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::vector< std::pair< std::string, int> > Exception::getStackTrace() const {
-    return stackTrace;
+std::vector<std::pair<std::string, int> > Exception::getStackTrace() const {
+    return this->data->stackTrace;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Exception::setStackTrace(
-    const std::vector< std::pair< std::string, int> >& trace ) {
-
-    this->stackTrace = trace;
+void Exception::setStackTrace(const std::vector<std::pair<std::string, int> >& trace) {
+    this->data->stackTrace = trace;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void Exception::printStackTrace() const {
-    printStackTrace( std::cerr );
+    printStackTrace(std::cerr);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Exception::printStackTrace( std::ostream& stream ) const {
+void Exception::printStackTrace(std::ostream& stream) const {
     stream << getStackTraceString();
 }
 
@@ -144,10 +165,10 @@ std::string Exception::getStackTraceStri
     std::ostringstream stream;
 
     // Write the message and each stack entry.
-    stream << message << std::endl;
-    for( unsigned int ix=0; ix<stackTrace.size(); ++ix ){
-        stream << "\tFILE: " << stackTrace[ix].first;
-        stream << ", LINE: " << stackTrace[ix].second;
+    stream << this->data->message << std::endl;
+    for (unsigned int ix = 0; ix < this->data->stackTrace.size(); ++ix) {
+        stream << "\tFILE: " << this->data->stackTrace[ix].first;
+        stream << ", LINE: " << this->data->stackTrace[ix].second;
         stream << std::endl;
     }
 
@@ -156,32 +177,38 @@ std::string Exception::getStackTraceStri
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Exception& Exception::operator =( const Exception& ex ){
-    this->message = ex.message;
-    this->stackTrace = ex.stackTrace;
-    this->initCause( ex.cause );
+Exception& Exception::operator =(const Exception& ex) {
+    this->data->message = ex.data->message;
+    this->data->stackTrace = ex.data->stackTrace;
+    this->data->cause = ex.data->cause;
     return *this;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Exception::initCause( const std::exception* cause ) {
+void Exception::initCause(const std::exception* cause) {
 
-    if( cause == NULL || cause == this ) {
+    if (cause == NULL || cause == this) {
         return;
     }
 
-    if( this->cause != NULL ) {
-        delete this->cause;
-    }
+    this->data->cause.reset(cause);
 
-    const Exception* ptrCause = dynamic_cast<const Exception*>( cause );
-    if( ptrCause == NULL ) {
-        this->cause = new Exception( __FILE__, __LINE__, cause->what() );
-    } else {
-        this->cause = ptrCause->clone();
+    if (this->data->message == "") {
+        this->data->message = cause->what();
     }
+}
 
-    if( this->message == "" ) {
-        this->message = cause->what();
-    }
+////////////////////////////////////////////////////////////////////////////////
+std::string Exception::getMessage() const {
+    return this->data->message;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+const std::exception*Exception:: getCause() const {
+    return this->data->cause.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+const char* Exception::what() const throw () {
+    return this->data->message.c_str();
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h Fri Oct 12 20:18:19 2012
@@ -27,8 +27,10 @@
 #include <stdarg.h>
 #include <sstream>
 
-namespace decaf{
-namespace lang{
+namespace decaf {
+namespace lang {
+
+    class ExceptionData;
 
     /*
      * Base class for all exceptions.
@@ -36,20 +38,7 @@ namespace lang{
     class DECAF_API Exception : public Throwable {
     protected:
 
-        /**
-         * The cause of this exception.
-         */
-        std::string message;
-
-        /**
-         * The Exception that caused this one to be thrown.
-         */
-        std::exception* cause;
-
-        /**
-         * The stack trace.
-         */
-        std::vector< std::pair< std::string, int> > stackTrace;
+        ExceptionData* data;
 
     public:
 
@@ -64,42 +53,52 @@ namespace lang{
          * @param ex
          *      The <code>Exception</code> instance to copy.
          */
-        Exception( const Exception& ex );
+        Exception(const Exception& ex);
 
         /**
          * Constructor
          *
          * @param cause
          *      Pointer to the exception that caused this one to
-         *      be thrown, the object is cloned caller retains ownership.
+         *      be thrown, the caller must ensure that it passes a
+         *      valid pointer as this object takes ownership of the
+         *      exception.
          */
-        Exception( const std::exception* cause );
+        Exception(const std::exception* cause);
 
         /**
          * Constructor - Initializes the file name and line number where
          * this message occurred.  Sets the message to report, using an
-         * optional list of arguments to parse into the message
-         * @param file The file name where exception occurs
-         * @param lineNumber The line number where the exception occurred.
-         * @param msg The message to report
-         * @param ... list of primitives that are formatted into the message
+         * optional list of arguments to parse into the message.
+         *
+         * @param file
+         *      The file name where exception occurs
+         * @param lineNumber
+         *      The line number where the exception occurred.
+         * @param msg
+         *      The message to report
+         * @param ...
+         *      list of primitives that are formatted into the message
          */
-        Exception( const char* file, const int lineNumber,
-                   const char* msg, ... );
+        Exception(const char* file, const int lineNumber, const char* msg, ...);
 
         /**
          * Constructor - Initializes the file name and line number where
          * this message occurred.  Sets the message to report, using an
-         * optional list of arguments to parse into the message
-         * @param file The file name where exception occurs
-         * @param lineNumber The line number where the exception occurred.
-         * @param cause The exception that was the cause for this one to be thrown.
-         * @param msg The message to report
-         * @param ... list of primitives that are formatted into the message
-         */
-        Exception( const char* file, const int lineNumber,
-                   const std::exception* cause,
-                   const char* msg, ... );
+         * optional list of arguments to parse into the message.
+         *
+         * @param file
+         *      The file name where exception occurs
+         * @param lineNumber
+         *      The line number where the exception occurred.
+         * @param cause
+         *      The exception that was the cause for this one to be thrown.
+         * @param msg
+         *      The message to report
+         * @param ...
+         *      list of primitives that are formatted into the message
+         */
+        Exception(const char* file, const int lineNumber, const std::exception* cause, const char* msg, ...);
 
         virtual ~Exception() throw();
 
@@ -107,9 +106,7 @@ namespace lang{
          * Gets the message for this exception.
          * @return Text formatted error message
          */
-        virtual std::string getMessage() const{
-            return message;
-        }
+        virtual std::string getMessage() const;
 
         /**
          * Gets the exception that caused this one to be thrown, this allows
@@ -117,55 +114,62 @@ namespace lang{
          * a particular exception but wishes to allow for the real causal
          * exception to be passed only in case the caller knows about that
          * type of exception and wishes to respond to it.
+         *
          * @returns a const pointer reference to the causal exception, if there
-         * was no cause associated with this exception then NULL is returned.
+         *          was no cause associated with this exception then NULL is returned.
          */
-        virtual const std::exception* getCause() const {
-            return this->cause;
-        }
+        virtual const std::exception* getCause() const;
 
         /**
          * Initializes the contained cause exception with the one given.  A copy
          * is made to avoid ownership issues.
-         * @param cause The exception that was the cause of this one.
+         *
+         * @param cause
+         *      The exception that was the cause of this one.
          */
-        virtual void initCause( const std::exception* cause );
+        virtual void initCause(const std::exception* cause);
 
         /**
-         * Implement method from std::exception
+         * Implement method from std::exception.
+         *
          * @return the const char* of <code>getMessage()</code>.
          */
-        virtual const char* what() const throw (){
-            return message.c_str();
-        }
+        virtual const char* what() const throw ();
 
         /**
          * Sets the cause for this exception.
-         * @param msg the format string for the msg.
-         * @param ... params to format into the string
+         *
+         * @param msg
+         *      The format string for the msg.
+         * @param ...
+         *      The params to format into the string.
          */
-        virtual void setMessage( const char* msg, ... );
+        virtual void setMessage(const char* msg, ...);
 
         /**
          * Adds a file/line number to the stack trace.
-         * @param file The name of the file calling this method (use __FILE__).
-         * @param lineNumber The line number in the calling file (use __LINE__).
+         *
+         * @param file
+         *      The name of the file calling this method (use __FILE__).
+         * @param lineNumber
+         *      The line number in the calling file (use __LINE__).
          */
-        virtual void setMark( const char* file, const int lineNumber );
+        virtual void setMark(const char* file, const int lineNumber);
 
         /**
          * Clones this exception.  This is useful for cases where you need
          * to preserve the type of the original exception as well as the message.
          * All subclasses should override.
+         *
          * @return Copy of this Exception object
          */
         virtual Exception* clone() const;
 
         /**
-         * Provides the stack trace for every point where
-         * this exception was caught, marked, and rethrown.  The first
-         * item in the returned vector is the first point where the mark
-         * was set (e.g. where the exception was created).
+         * Provides the stack trace for every point where this exception was caught,
+         * marked, and rethrown.  The first item in the returned vector is the first
+         * point where the mark was set (e.g. where the exception was created).
+         *
          * @return the stack trace.
          */
         virtual std::vector< std::pair< std::string, int> > getStackTrace() const;
@@ -177,28 +181,32 @@ namespace lang{
 
         /**
          * Prints the stack trace to the given output stream.
-         * @param stream the target output stream.
+         *
+         * @param stream
+         *      the target output stream.
          */
-        virtual void printStackTrace( std::ostream& stream ) const;
+        virtual void printStackTrace(std::ostream& stream) const;
 
         /**
          * Gets the stack trace as one contiguous string.
-         * @return string with formatted stack trace data
+         *
+         * @return string with formatted stack trace data.
          */
         virtual std::string getStackTraceString() const;
 
         /**
-         * Assignment operator.
-         * @param ex const reference to another Exception
+         * Assignment operator, copies one Exception to another.
+         *
+         * @param ex
+         *      const reference to another Exception
          */
-        Exception& operator =( const Exception& ex );
+        Exception& operator =(const Exception& ex);
 
     protected:
 
-        virtual void setStackTrace(
-            const std::vector< std::pair< std::string, int> >& trace );
+        virtual void setStackTrace(const std::vector<std::pair<std::string, int> >& trace);
 
-        virtual void buildMessage( const char* format, va_list& vargs );
+        virtual void buildMessage(const char* format, va_list& vargs);
 
    };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/ExceptionDefines.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/ExceptionDefines.h?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/ExceptionDefines.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/exceptions/ExceptionDefines.h Fri Oct 12 20:18:19 2012
@@ -38,7 +38,7 @@
  */
 #define DECAF_CATCH_EXCEPTION_CONVERT( sourceType, targetType ) \
     catch( sourceType& ex ){ \
-        targetType target( &ex ); \
+        targetType target( ex.clone() ); \
         target.setMark( __FILE__, __LINE__ ); \
         throw target; \
     }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/FutureTask.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/FutureTask.h?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/FutureTask.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/FutureTask.h Fri Oct 12 20:18:19 2012
@@ -160,7 +160,7 @@ namespace concurrent {
                     throw CancellationException();
                 }
                 if (exception != NULL) {
-                    throw ExecutionException(exception.get());
+                    throw ExecutionException(exception->clone());
                 }
                 return result;
             }
@@ -173,7 +173,7 @@ namespace concurrent {
                     throw CancellationException();
                 }
                 if (exception != NULL) {
-                    throw ExecutionException(exception.get());
+                    throw ExecutionException(exception->clone());
                 }
                 return result;
             }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp Fri Oct 12 20:18:19 2012
@@ -253,7 +253,7 @@ int InflaterInputStream::doReadArrayBoun
                 }
 
                 IOException ex( __FILE__, __LINE__, "Error from Inflater" );
-                ex.initCause( &e );
+                ex.initCause(e.clone());
                 throw ex;
             }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ExceptionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ExceptionTest.cpp?rev=1397715&r1=1397714&r2=1397715&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ExceptionTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ExceptionTest.cpp Fri Oct 12 20:18:19 2012
@@ -38,7 +38,7 @@ void ExceptionTest::testCtors() {
     CPPUNIT_ASSERT( exception2.getCause() == NULL );
     CPPUNIT_ASSERT( exception2.getMessage() == "EXCEPTION_2" );
 
-    Exception exception3( __FILE__, __LINE__, &exception1, "EXCEPTION_3" );
+    Exception exception3( __FILE__, __LINE__, exception1.clone(), "EXCEPTION_3" );
 
     CPPUNIT_ASSERT( exception3.getCause() != NULL );
     CPPUNIT_ASSERT( std::string( exception3.getCause()->what() ) == "EXCEPTION_1" );
@@ -49,7 +49,7 @@ void ExceptionTest::testCtors() {
     CPPUNIT_ASSERT( exception4.getMessage() == "EXCEPTION_1" );
 
     std::runtime_error runtime( "RUNTIME" );
-    Exception exception5( &runtime );
+    Exception exception5( new std::runtime_error(runtime) );
     CPPUNIT_ASSERT( exception5.getCause() != NULL );
     CPPUNIT_ASSERT( exception5.getMessage() == "RUNTIME" );
 }
@@ -102,11 +102,11 @@ void ExceptionTest::testInitCause() {
     std::runtime_error exception1("RUNTIME");
     Exception exception2( __FILE__, __LINE__, "EXCEPTION" );
 
-    ex.initCause( &exception1 );
+    ex.initCause( new std::runtime_error(exception1) );
     CPPUNIT_ASSERT( ex.getCause() != NULL );
     CPPUNIT_ASSERT( std::string( ex.getCause()->what() ) == "RUNTIME" );
 
-    ex.initCause( &exception2 );
+    ex.initCause( exception2.clone() );
     CPPUNIT_ASSERT( ex.getCause() != NULL );
     CPPUNIT_ASSERT( std::string( ex.getCause()->what() ) == "EXCEPTION" );