brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [23/50] brooklyn-server git commit: Tidy up the Exceptions class - Better javadoc - Unwrap ExecutionExceptions
Date Mon, 01 Feb 2016 17:49:09 GMT
Tidy up the Exceptions class
- Better javadoc
- Unwrap ExecutionExceptions


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f7ac179b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f7ac179b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f7ac179b

Branch: refs/heads/0.5.0
Commit: f7ac179bd95de7482564bf3a021768641a56d5d2
Parents: b3a1b05
Author: Andrew Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Wed Apr 3 23:14:45 2013 +0100
Committer: Andrew Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Fri Apr 19 10:37:17 2013 +0100

----------------------------------------------------------------------
 .../brooklyn/util/exceptions/Exceptions.java    | 27 +++++++++++++++-----
 .../exceptions/RuntimeInterruptedException.java |  6 ++---
 2 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f7ac179b/core/src/main/java/brooklyn/util/exceptions/Exceptions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/exceptions/Exceptions.java b/core/src/main/java/brooklyn/util/exceptions/Exceptions.java
index 6428f85..e4866c9 100644
--- a/core/src/main/java/brooklyn/util/exceptions/Exceptions.java
+++ b/core/src/main/java/brooklyn/util/exceptions/Exceptions.java
@@ -5,25 +5,38 @@ import static com.google.common.base.Throwables.getCausalChain;
 import static com.google.common.collect.Iterables.find;
 
 import java.util.NoSuchElementException;
+import java.util.concurrent.ExecutionException;
 
 import com.google.common.base.Throwables;
 
 public class Exceptions {
 
-    /** like guava {@link Throwables#propagate(Throwable)}, 
-     * but set interrupted if interrupted exception (why doesn't guava do this?!), 
-     * and throw {@link RuntimeInterruptedException} */
+    /**
+     * Propagate a {@link Throwable} as a {@link RuntimeException}.
+     * <p>
+     * Like Guava {@link Throwables#propagate(Throwable)} but throws {@link RuntimeInterruptedException}
+     * to handle {@link InterruptedException}s and unpacks the {@link Exception#getCause()
cause} and propagates
+     * it for {@link ExecutionException}s.
+     */
     public static RuntimeException propagate(Throwable throwable) {
         if (throwable instanceof InterruptedException)
-            throw new RuntimeInterruptedException((InterruptedException)throwable);
+            throw new RuntimeInterruptedException((InterruptedException) throwable);
+        if (throwable instanceof ExecutionException)
+            return Throwables.propagate(throwable.getCause());
         return Throwables.propagate(throwable);
     }
 
-    /** propagates exceptions which are fatal, ie those which one rarely if ever wants to
capture
-     * (such as InterruptedException and Errors) */
+    /** 
+     * Propagate exceptions which are fatal.
+     * <p>
+     * Propagates only those exceptions which one rarely (if ever) wants to capture,
+     * such as {@link InterruptedException} and {@link Error}s.
+     */
     public static void propagateIfFatal(Throwable throwable) {
         if (throwable instanceof InterruptedException)
-            throw new RuntimeInterruptedException((InterruptedException)throwable);
+            throw new RuntimeInterruptedException((InterruptedException) throwable);
+        if (throwable instanceof ExecutionException)
+            propagateIfFatal(throwable.getCause());
         if (throwable instanceof Error)
             throw (Error) throwable;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f7ac179b/core/src/main/java/brooklyn/util/exceptions/RuntimeInterruptedException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/exceptions/RuntimeInterruptedException.java
b/core/src/main/java/brooklyn/util/exceptions/RuntimeInterruptedException.java
index f1ba196..2083131 100644
--- a/core/src/main/java/brooklyn/util/exceptions/RuntimeInterruptedException.java
+++ b/core/src/main/java/brooklyn/util/exceptions/RuntimeInterruptedException.java
@@ -2,11 +2,11 @@ package brooklyn.util.exceptions;
 
 /**
  * A {@link RuntimeException} that is thrown when a Thread is interrupted.
- *
+ * <p>
  * This exception is useful if a Thread needs to be interrupted, but the {@link InterruptedException}
can't be thrown
  * because it is checked.
- *
- * When the RuntimeInterruptedException is created, it will automatically set the interrupt
status on the calling
+ * <p>
+ * When the {@link RuntimeInterruptedException} is created, it will automatically set the
interrupt status on the calling
  * thread.
  *
  * @author Peter Veentjer.


Mime
View raw message