Class Exceptions
- java.lang.Object
-
- com.github.tomakehurst.wiremock.common.Exceptions
-
public class Exceptions extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Exceptions.RunnableWithException
-
Constructor Summary
Constructors Constructor Description Exceptions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
renderStackTrace(java.lang.Throwable t)
static void
throwUnchecked(java.lang.Throwable ex)
static <T> T
throwUnchecked(java.lang.Throwable ex, java.lang.Class<T> returnType)
Because this method throws an unchecked exception, when it is called in a method with a return type the compiler does not know the method is exiting, requiring a further line to return null or throw an unchecked exception directly.static void
uncheck(Exceptions.RunnableWithException work)
static <T> T
uncheck(java.util.concurrent.Callable<T> work, java.lang.Class<T> returnType)
-
-
-
Method Detail
-
throwUnchecked
public static <T> T throwUnchecked(java.lang.Throwable ex, java.lang.Class<T> returnType)
Because this method throws an unchecked exception, when it is called in a method with a return type the compiler does not know the method is exiting, requiring a further line to return null or throw an unchecked exception directly. This generified method allows this to be avoided by tricking the compiler by adding a return statement as so:String someMethod() { try { somethingThatThrowsException(); } catch (Exception e) { return throwUnchecked(e, String.class); // does not actually return, throws the exception } }
- Parameters:
ex
- The exception that will be thrown, unwrapped and uncheckedreturnType
- trick to persuade the compiler that a method returns appropriately- Returns:
- Never returns, always throws the passed in exception
-
throwUnchecked
public static void throwUnchecked(java.lang.Throwable ex)
- Parameters:
ex
- The exception that will be thrown, unwrapped and unchecked
-
uncheck
public static <T> T uncheck(java.util.concurrent.Callable<T> work, java.lang.Class<T> returnType)
-
uncheck
public static void uncheck(Exceptions.RunnableWithException work)
-
renderStackTrace
public static java.lang.String renderStackTrace(java.lang.Throwable t)
-
-