Author: ritchiem
Date: Thu Nov 6 01:54:54 2008
New Revision: 711818
URL: http://svn.apache.org/viewvc?rev=711818&view=rev
Log:
QPID-1434 : Add ability to rethrow AMQExceptions
Modified:
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java
Modified:
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java?rev=711818&r1=711817&r2=711818&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java
(original)
+++
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java
Thu Nov 6 01:54:54 2008
@@ -90,4 +90,34 @@
{
return true;
}
+
+ /**
+ * Rethrown this exception as a new exception.
+ *
+ * Attempt to create a new exception of the same class if they hav the
default constructor of:
+ * {AMQConstant.class, String.class, Throwable.class}
+ *
+ * Individual subclasses may override as requried to create a new instance.
+ *
+ * @throws AMQException
+ */
+ public void rethrow() throws AMQException
+ {
+ Class amqeClass = this.getClass();
+ Class<?>[] paramClasses = {AMQConstant.class, String.class,
Throwable.class};
+ Object[] params = {getErrorCode(), getMessage(), this};
+
+ AMQException newAMQE;
+
+ try
+ {
+ newAMQE = (AMQException)
amqeClass.getConstructor(paramClasses).newInstance(params);
+ }
+ catch (Exception creationException)
+ {
+ newAMQE = new AMQException(getErrorCode(), getMessage(), this);
+ }
+
+ throw newAMQE;
+ }
}