From d8b43ab738b5602bdda79337057da6b0996273ca Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Thu, 6 Nov 2008 09:54:54 +0000 Subject: QPID-1434 : Add ability to rethrow AMQExceptions git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@711818 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/qpid/AMQException.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'qpid/java/common/src') diff --git a/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java b/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java index eda532b64e..1cfd7e3134 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/AMQException.java @@ -90,4 +90,34 @@ public class AMQException extends Exception { 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; + } } -- cgit v1.2.1