-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLaunderThrowable.java
More file actions
24 lines (22 loc) · 651 Bytes
/
LaunderThrowable.java
File metadata and controls
24 lines (22 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package net.jcip.examples;
/**
* StaticUtilities
*
* @author Brian Goetz and Tim Peierls
*/
public class LaunderThrowable {
/**
* Coerce an unchecked Throwable to a RuntimeException
* <p/>
* If the Throwable is an Error, throw it; if it is a
* RuntimeException return it, otherwise throw IllegalStateException
*/
public static RuntimeException launderThrowable(Throwable t) {
if (t instanceof RuntimeException)
return (RuntimeException) t;
else if (t instanceof Error)
throw (Error) t;
else
throw new IllegalStateException("Not unchecked", t);
}
}