Interface TestExecutionExceptionHandler
-
- All Superinterfaces:
Extension
- All Known Implementing Classes:
ExpectedExceptionSupport
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface @API(status=STABLE, since="5.0") public interface TestExecutionExceptionHandler extends Extension
TestExecutionExceptionHandler
defines the API forExtensions
that wish to handle exceptions thrown during test execution.In this context, test execution refers to the physical invocation of a
@Test
method and not to any test-level extensions or callbacks.Common use cases include swallowing an exception if it's anticipated or rolling back a transaction in certain error scenarios.
Implementations must provide a no-args constructor.
- Since:
- 5.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
handleTestExecutionException(ExtensionContext context, java.lang.Throwable throwable)
Handle the suppliedthrowable
.
-
-
-
Method Detail
-
handleTestExecutionException
void handleTestExecutionException(ExtensionContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Handle the suppliedthrowable
.Implementors must perform one of the following.
- Swallow the supplied
throwable
, thereby preventing propagation. - Rethrow the supplied
throwable
as is. - Throw a new exception, potentially wrapping the supplied
throwable
.
If the supplied
throwable
is swallowed, subsequentTestExecutionExceptionHandlers
will not be invoked; otherwise, the next registeredTestExecutionExceptionHandler
(if there is one) will be invoked with anyThrowable
thrown by this handler.Note that the
execution exception
in the suppliedExtensionContext
will not contain theThrowable
thrown during invocation of the corresponding@Test
method.- Parameters:
context
- the current extension context; nevernull
throwable
- theThrowable
to handle; nevernull
- Throws:
java.lang.Throwable
- Swallow the supplied
-
-