public final class Exceptions
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Exceptions.ExceptionDeclarer
A utility type for declaring exceptions.
|
static class |
Exceptions.UncheckedMarker
This error type cannot be thrown; it exists to allow
callers of
throwChecked(Throwable)
to express intent with the throw keyword. |
Modifier and Type | Method and Description |
---|---|
static <T extends java.lang.Throwable> |
expected()
Declares that the scope expects a checked exception.
|
static Exceptions.UncheckedMarker |
throwChecked(java.lang.Throwable t)
Throws any type of
Throwable as an unchecked type. |
public static Exceptions.UncheckedMarker throwChecked(java.lang.Throwable t)
Throws any type of Throwable
as an unchecked type.
void foo(Closeable c) { try { c.close(); } catch(IOException e) { throw Exceptions.throwChecked(e); } }
t
- the (non-null) type to throwpublic static <T extends java.lang.Throwable> Exceptions.ExceptionDeclarer expected() throws T extends java.lang.Throwable
Declares that the scope expects a checked exception. Use this method to catch a checked exception that is not detected by the compiler.
Usage:
abstract void bar(); void foo() { try { Exceptions .<IOException>expected() .<MethodNotFoundException>expected(); bar(); } catch(IOException|MethodNotFoundException e) { // handle error } }
T
- the type of exception expectedT
- the exceptionT extends java.lang.Throwable