Class UncheckedException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.github.robtimus.function.throwing.UncheckedException
-
- All Implemented Interfaces:
Serializable
public final class UncheckedException extends RuntimeException
Wraps a throwable with an unchecked exception.- Author:
- Rob Spoor
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T,X extends Throwable>
TthrowCauseAs(Class<X> errorType)Throws the wrapped throwable as an instance of a specific error type.<T,X1 extends Throwable,X2 extends Throwable>
TthrowCauseAsOneOf(Class<X1> errorType1, Class<X2> errorType2)Throws the wrapped throwable as an instance of one of a set of specific error types.<T,X1 extends Throwable,X2 extends Throwable,X3 extends Throwable>
TthrowCauseAsOneOf(Class<X1> errorType1, Class<X2> errorType2, Class<X3> errorType3)Throws the wrapped throwable as an instance of one of a set of specific error types.static UncheckedExceptionwithoutStackTrace(String message, Throwable cause)Creates a new exception with a stack trace of its own.static UncheckedExceptionwithoutStackTrace(Throwable cause)Creates a new exception without a stack trace of its own.static UncheckedExceptionwithStackTrace(String message, Throwable cause)Creates a new exception with a stack trace of its own.static UncheckedExceptionwithStackTrace(Throwable cause)Creates a new exception with a stack trace of its own.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Method Detail
-
withStackTrace
public static UncheckedException withStackTrace(Throwable cause)
Creates a new exception with a stack trace of its own.- Parameters:
cause- The throwable to wrap.- Returns:
- The created exception.
- Throws:
NullPointerException- If the given throwable isnull.
-
withStackTrace
public static UncheckedException withStackTrace(String message, Throwable cause)
Creates a new exception with a stack trace of its own.- Parameters:
message- The optional detail message.cause- The throwable to wrap.- Returns:
- The created exception.
- Throws:
NullPointerException- If the given throwable isnull.
-
withoutStackTrace
public static UncheckedException withoutStackTrace(Throwable cause)
Creates a new exception without a stack trace of its own. This makes the created exception more lightweight.- Parameters:
cause- The throwable to wrap.- Returns:
- The created exception.
- Throws:
NullPointerException- If the given throwable isnull.
-
withoutStackTrace
public static UncheckedException withoutStackTrace(String message, Throwable cause)
Creates a new exception with a stack trace of its own. This makes the created exception more lightweight.- Parameters:
message- The optional detail message.cause- The throwable to wrap.- Returns:
- The created exception.
- Throws:
NullPointerException- If the given throwable isnull.
-
throwCauseAs
public <T,X extends Throwable> T throwCauseAs(Class<X> errorType) throws X extends Throwable
Throws the wrapped throwable as an instance of a specific error type.- Type Parameters:
T- The return type. This allows this method to be used with return statements.X- The type of error to throw.- Parameters:
errorType- The type of error to throw.- Returns:
- Nothing. This method always thrown an exception.
- Throws:
NullPointerException- If the given error type isnull.X- The wrapped throwable cast to an instance of the given error type.IllegalStateException- If the wrapped throwable is not an instance of the given error type.X extends Throwable
-
throwCauseAsOneOf
public <T,X1 extends Throwable,X2 extends Throwable> T throwCauseAsOneOf(Class<X1> errorType1, Class<X2> errorType2) throws X1 extends Throwable, X2 extends Throwable
Throws the wrapped throwable as an instance of one of a set of specific error types.- Type Parameters:
T- The return type. This allows this method to be used with return statements.X1- The type of the first possible error to throw.X2- The type of the second possible error to throw.- Parameters:
errorType1- The type of the first possible error to throw.errorType2- The type of the second possible error to throw.- Returns:
- Nothing. This method always thrown an exception.
- Throws:
NullPointerException- If either given error type isnull.X1- The wrapped throwable cast to an instance of the first given error type.X2- The wrapped throwable cast to an instance of the second given error type.IllegalStateException- If the wrapped throwable is not an instance of either given error type.X1 extends Throwable
-
throwCauseAsOneOf
public <T,X1 extends Throwable,X2 extends Throwable,X3 extends Throwable> T throwCauseAsOneOf(Class<X1> errorType1, Class<X2> errorType2, Class<X3> errorType3) throws X1 extends Throwable, X2 extends Throwable, X3 extends Throwable
Throws the wrapped throwable as an instance of one of a set of specific error types.- Type Parameters:
T- The return type. This allows this method to be used with return statements.X1- The type of the first possible error to throw.X2- The type of the second possible error to throw.X3- The type of the third possible error to throw.- Parameters:
errorType1- The type of the first possible error to throw.errorType2- The type of the second possible error to throw.errorType3- The type of the third possible error to throw.- Returns:
- Nothing. This method always thrown an exception.
- Throws:
NullPointerException- If any given error type isnull.X1- The wrapped throwable cast to an instance of the first given error type.X2- The wrapped throwable cast to an instance of the second given error type.X3- The wrapped throwable cast to an instance of the third given error type.IllegalStateException- If the wrapped throwable is not an instance of any given error type.X1 extends Throwable
-
-