diff options
author | Martin Ritchie <ritchiem@apache.org> | 2008-11-06 12:21:37 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2008-11-06 12:21:37 +0000 |
commit | 324d26687919a5e1fc3de44f2998dce700e2149a (patch) | |
tree | 8d78f6bdf564024b777e9e088b08a48716100d83 /java/common | |
parent | 92914dcf983f5328a19648950ab8d2c42ca77925 (diff) | |
download | qpid-python-324d26687919a5e1fc3de44f2998dce700e2149a.tar.gz |
QPID-1434 : Changed rethrow() name based on feedback from Rob
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@711848 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
-rw-r--r-- | java/common/src/main/java/org/apache/qpid/AMQException.java | 7 | ||||
-rw-r--r-- | java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java | 60 |
2 files changed, 22 insertions, 45 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/AMQException.java b/java/common/src/main/java/org/apache/qpid/AMQException.java index 1cfd7e3134..be335c5dba 100644 --- a/java/common/src/main/java/org/apache/qpid/AMQException.java +++ b/java/common/src/main/java/org/apache/qpid/AMQException.java @@ -98,10 +98,9 @@ public class AMQException extends Exception * {AMQConstant.class, String.class, Throwable.class} * * Individual subclasses may override as requried to create a new instance. - * - * @throws AMQException + * */ - public void rethrow() throws AMQException + public AMQException cloneForCurrentThread() { Class amqeClass = this.getClass(); Class<?>[] paramClasses = {AMQConstant.class, String.class, Throwable.class}; @@ -118,6 +117,6 @@ public class AMQException extends Exception newAMQE = new AMQException(getErrorCode(), getMessage(), this); } - throw newAMQE; + return newAMQE; } } diff --git a/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java b/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java index 853dc85592..ef6cd41492 100644 --- a/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java +++ b/java/common/src/test/java/org/apache/qpid/AMQExceptionTest.java @@ -42,14 +42,10 @@ public class AMQExceptionTest extends TestCase { AMQException test = new AMQException(AMQConstant.ACCESS_REFUSED, "refused", new RuntimeException()); - try - { - reThrowException(test); - } - catch (AMQException e) - { - assertEquals("Exception not of correct class", AMQException.class, e.getClass()); - } + AMQException e = reThrowException(test); + + assertEquals("Exception not of correct class", AMQException.class, e.getClass()); + } /** @@ -60,14 +56,9 @@ public class AMQExceptionTest extends TestCase AMQFrameDecodingException test = new AMQFrameDecodingException(AMQConstant.INTERNAL_ERROR, "Error", new Exception()); - try - { - reThrowException(test); - } - catch (AMQException e) - { - assertEquals("Exception not of correct class", AMQFrameDecodingException.class, e.getClass()); - } + AMQException e = reThrowException(test); + + assertEquals("Exception not of correct class", AMQFrameDecodingException.class, e.getClass()); } /** @@ -77,14 +68,10 @@ public class AMQExceptionTest extends TestCase public void testRethrowAMQESubclassNoConstructor() { AMQExceptionSubclass test = new AMQExceptionSubclass("Invalid Argument Exception"); - try - { - reThrowException(test); - } - catch (AMQException e) - { - assertEquals("Exception not of correct class", AMQException.class, e.getClass()); - } + + AMQException e = reThrowException(test); + + assertEquals("Exception not of correct class", AMQException.class, e.getClass()); } /** @@ -92,25 +79,16 @@ public class AMQExceptionTest extends TestCase * @param test Exception to rethrow * @throws AMQException the rethrown exception */ - private void reThrowException(AMQException test) throws AMQException + private AMQException reThrowException(AMQException test) { - try - { - test.rethrow(); - } - catch (AMQException amqe) - { - assertEquals("Error code does not match.", test.getErrorCode(), amqe.getErrorCode()); - assertTrue("Exception message does not start as expected.", amqe.getMessage().startsWith(test.getMessage())); - assertEquals("Test Exception is not set as the cause", test, amqe.getCause()); - assertEquals("Cause is not correct", test.getCause(), amqe.getCause().getCause()); - throw amqe; - } - catch (Throwable e) - { - fail("Throwable recieved when AMQException expected:" + e); - } + AMQException amqe = test.cloneForCurrentThread(); + + assertEquals("Error code does not match.", test.getErrorCode(), amqe.getErrorCode()); + assertTrue("Exception message does not start as expected.", amqe.getMessage().startsWith(test.getMessage())); + assertEquals("Test Exception is not set as the cause", test, amqe.getCause()); + assertEquals("Cause is not correct", test.getCause(), amqe.getCause().getCause()); + return amqe; } /** |