commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r1688614 - /commons/sandbox/commons-inject/trunk/src/main/java/org/apache/commons/inject/util/Exceptions.java
Date Wed, 01 Jul 2015 10:46:23 GMT
Author: jochen
Date: Wed Jul  1 10:46:22 2015
New Revision: 1688614

URL: http://svn.apache.org/r1688614
Log:
Adding Exceptions.show(Throwable, Class).

Modified:
    commons/sandbox/commons-inject/trunk/src/main/java/org/apache/commons/inject/util/Exceptions.java

Modified: commons/sandbox/commons-inject/trunk/src/main/java/org/apache/commons/inject/util/Exceptions.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-inject/trunk/src/main/java/org/apache/commons/inject/util/Exceptions.java?rev=1688614&r1=1688613&r2=1688614&view=diff
==============================================================================
--- commons/sandbox/commons-inject/trunk/src/main/java/org/apache/commons/inject/util/Exceptions.java
(original)
+++ commons/sandbox/commons-inject/trunk/src/main/java/org/apache/commons/inject/util/Exceptions.java
Wed Jul  1 10:46:22 2015
@@ -46,4 +46,18 @@ public class Exceptions {
 			return new UndeclaredThrowableException(pTh);
 		}
 	}
+
+	public static <E extends Throwable> RuntimeException show(Throwable pTh, Class<E>
pClass) throws E{
+		if (pTh == null) {
+			return new NullPointerException("The Throwable to show must not be null.");
+		} else if (pTh instanceof RuntimeException) {
+			return (RuntimeException) pTh;
+		} else if (pTh instanceof Error) {
+			throw (Error) pTh;
+		} else if (pClass.isAssignableFrom(pTh.getClass())) {
+			throw pClass.cast(pTh);
+		} else {
+			return new UndeclaredThrowableException(pTh);
+		}
+	}
 }



Mime
View raw message