activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1450446 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq: commands/BrokerError.cpp commands/BrokerError.h core/ActiveMQConnection.cpp exceptions/ActiveMQException.cpp exceptions/ActiveMQException.h
Date Tue, 26 Feb 2013 21:33:29 GMT
Author: tabish
Date: Tue Feb 26 21:33:29 2013
New Revision: 1450446

URL: http://svn.apache.org/r1450446
Log:
https://issues.apache.org/jira/browse/AMQCPP-467

Improves the way CMSExceptions are created from broker errors and starts on getting the matching
type thrown from CMS API methods.

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

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=1450446&r1=1450445&r2=1450446&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 Tue
Feb 26 21:33:29 2013
@@ -20,6 +20,7 @@
 #include <decaf/lang/exceptions/NullPointerException.h>
 #include <decaf/util/StringTokenizer.h>
 #include <string>
+#include <utility>
 
 #include <cms/CMSException.h>
 #include <cms/CMSSecurityException.h>
@@ -80,57 +81,68 @@ Pointer<commands::Command> BrokerError::
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-decaf::lang::Exception BrokerError::createExceptionObject() {
-
-    StringTokenizer tokenizer(this->exceptionClass);
-
+ActiveMQException BrokerError::createExceptionObject() {
 
+    StringTokenizer tokenizer(this->exceptionClass, ".");
     std::string exceptionClass = this->exceptionClass;
 
     while (tokenizer.hasMoreTokens()) {
         exceptionClass = tokenizer.nextToken();
     }
 
+    std::vector<std::pair<std::string, int> > cmsStackTrace;
+
+    std::vector< Pointer<StackTraceElement> >::const_iterator stackIter = this->stackTraceElements.begin();
+    for (; stackIter != stackTraceElements.end(); ++stackIter) {
+        Pointer<StackTraceElement> element = *stackIter;
+        if (element == NULL) {
+            continue;
+        }
+
+        std::string name = element->ClassName + "." + element->MethodName + "(" +
+                           element->FileName + ")";
+
+        cmsStackTrace.push_back(std::make_pair(name, element->LineNumber));
+    }
+
     cms::CMSException* cause = NULL;
 
     if (exceptionClass == "JMSException") {
-        cause = new cms::CMSException(this->message);
+        cause = new cms::CMSException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "JMSSecurityException") {
-        cause = new cms::CMSSecurityException(this->message);
+        cause = new cms::CMSSecurityException(this->message, NULL, cmsStackTrace);
+    } else if (exceptionClass == "SecurityException") {
+        cause = new cms::CMSSecurityException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "MessageEOFException") {
-        cause = new cms::MessageEOFException(this->message);
+        cause = new cms::MessageEOFException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "MessageFormatException") {
-        cause = new cms::MessageFormatException(this->message);
+        cause = new cms::MessageFormatException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "MessageNotReadableException") {
-        cause = new cms::MessageNotReadableException(this->message);
+        cause = new cms::MessageNotReadableException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "MessageNotWriteableException") {
-        cause = new cms::MessageNotWriteableException(this->message);
+        cause = new cms::MessageNotWriteableException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "InvalidClientIdException") {
-        cause = new cms::InvalidClientIdException(this->message);
+        cause = new cms::InvalidClientIdException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "InvalidDestinationException") {
-        cause = new cms::InvalidDestinationException(this->message);
+        cause = new cms::InvalidDestinationException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "InvalidSelectorException") {
-        cause = new cms::InvalidSelectorException(this->message);
+        cause = new cms::InvalidSelectorException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "IllegalStateException") {
-        cause = new cms::IllegalStateException(this->message);
+        cause = new cms::IllegalStateException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "ResourceAllocationException") {
-        cause = new cms::ResourceAllocationException(this->message);
+        cause = new cms::ResourceAllocationException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "TransactionInProgressException") {
-        cause = new cms::TransactionInProgressException(this->message);
+        cause = new cms::TransactionInProgressException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "TransactionRolledBackException") {
-        cause = new cms::TransactionRolledBackException(this->message);
+        cause = new cms::TransactionRolledBackException(this->message, NULL, cmsStackTrace);
     } else if (exceptionClass == "UnsupportedOperationException") {
-        cause = new cms::UnsupportedOperationException(this->message);
+        cause = new cms::UnsupportedOperationException(this->message, NULL, cmsStackTrace);
     } else {
-        if (exCause != NULL) {
-            cause = new cms::CMSException(this->message);
-        } else {
-            cause = new cms::CMSException(this->exCause->getMessage());
-        }
+        cause = new cms::CMSException(this->message, NULL, cmsStackTrace);
     }
 
-    // Wrap in a Decaf exception to carry the pointer until it can be
+    // Wrap in a activemq exception wrapper 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;
+    ActiveMQException wrapper(__FILE__, __LINE__, cause, this->getMessage().c_str());
+    return wrapper;
 }

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=1450446&r1=1450445&r2=1450446&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 Tue
Feb 26 21:33:29 2013
@@ -20,7 +20,7 @@
 
 #include <activemq/util/Config.h>
 #include <activemq/commands/BaseCommand.h>
-#include <decaf/lang/Exception.h>
+#include <activemq/exceptions/ActiveMQException.h>
 #include <decaf/lang/Pointer.h>
 
 #include <string>
@@ -180,14 +180,14 @@ namespace commands {
         }
 
         /**
-         * Creates and returns a Decaf Exception object that contains the error data from
the Broker.
+         * Creates and returns a ActiveMQException 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
+         * @return a new instance of an ActiveMQException
          */
-        decaf::lang::Exception createExceptionObject();
+        exceptions::ActiveMQException 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=1450446&r1=1450445&r2=1450446&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
Tue Feb 26 21:33:29 2013
@@ -1249,18 +1249,11 @@ Pointer<Response> ActiveMQConnection::sy
         commands::ExceptionResponse* exceptionResponse = dynamic_cast<ExceptionResponse*>(response.get());
 
         if (exceptionResponse != NULL) {
-
-            Exception ex = exceptionResponse->getException()->createExceptionObject();
-            if (ex.getCause() != NULL) {
-                throw *(ex.getCause());
-            }
-
-            throw BrokerException(__FILE__, __LINE__, exceptionResponse->getException()->getMessage().c_str());
+            throw exceptionResponse->getException()->createExceptionObject();
         }
 
         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)
@@ -1283,7 +1276,6 @@ void ActiveMQConnection::asyncRequest(Po
         Pointer<ResponseCallback> callback(new AsyncResponseCallback(this->config,
onComplete));
         this->config->transport->asyncRequest(command, callback);
     }
-    AMQ_CATCH_RETHROW(cms::CMSException)
     AMQ_CATCH_RETHROW(ActiveMQException)
     AMQ_CATCH_EXCEPTION_CONVERT(IOException, ActiveMQException)
     AMQ_CATCH_EXCEPTION_CONVERT(decaf::lang::exceptions::UnsupportedOperationException, 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=1450446&r1=1450445&r2=1450446&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
Tue Feb 26 21:33:29 2013
@@ -42,7 +42,20 @@ ActiveMQException::ActiveMQException(con
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-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);
+
+    // Set the first mark for this exception.
+    Exception::setMark(file, lineNumber);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ActiveMQException::ActiveMQException(const char* file, const int lineNumber, const std::exception*
cause, const char* msg, ...) :
+    decaf::lang::Exception(cause) {
 
     va_list vargs;
     va_start(vargs, msg);

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=1450446&r1=1450445&r2=1450446&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
Tue Feb 26 21:33:29 2013
@@ -26,8 +26,8 @@
 #include <decaf/lang/Exception.h>
 #include <activemq/exceptions/ExceptionDefines.h>
 
-namespace activemq{
-namespace exceptions{
+namespace activemq {
+namespace exceptions {
 
     /*
      * Base class for all exceptions.
@@ -72,6 +72,24 @@ namespace exceptions{
          */
         ActiveMQException(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
+         */
+        ActiveMQException(const char* file, const int lineNumber, const std::exception* cause,
const char* msg, ...);
+
         virtual ~ActiveMQException() throw();
 
         /**



Mime
View raw message