public class Intercept extends Object
| Constructor and Description |
|---|
Intercept() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Throwable> |
intercept(Class<T> exceptionType,
RunnableWithException throwing)
Intercept exceptions of type <code>exceptionType</code> and fail if no such
exception or an exception with an incompatible type was thrown.
|
static <T extends Throwable> |
intercept(Class<T> exceptionType,
String messageRegex,
RunnableWithException throwing)
Intercept exceptions of type <code>exceptionType</code> and fail if no such
exception or an exception with an incompatible type was thrown or it the
message does not match a given pattern.
|
public static <T extends Throwable> T intercept(Class<T> exceptionType, RunnableWithException throwing) throws Exception
Intercept exceptions of type <code>exceptionType</code> and fail if no such exception or an exception with an incompatible type was thrown.
exceptionType - The exception type to intercept.throwing - The execution block which is expected to throw the exception.Exception - If no exception was thrown or an exception with an incompatible
type was thrown.public static <T extends Throwable> T intercept(Class<T> exceptionType, String messageRegex, RunnableWithException throwing) throws Exception
Intercept exceptions of type <code>exceptionType</code> and fail if no such exception or an exception with an incompatible type was thrown or it the message does not match a given pattern.
exceptionType - The exception type to intercept.messageRegex - A regular expression pattern to match the expected message. See
Pattern for details. If you just want to pass the exact
text message, you should surround your message string with "\\Q"
and "\\E".throwing - The execution block which is expected to throw the exception.Exception - If no exception was thrown or an exception with an incompatible
type was thrown or if the message of the exception did not match
the expected pattern.Copyright © 2019. All rights reserved.