Interface LifecycleMethodExecutionExceptionHandler
-
- All Superinterfaces:
Extension
@API(status=EXPERIMENTAL, since="5.5") public interface LifecycleMethodExecutionExceptionHandler extends ExtensionLifecycleMethodExecutionExceptionHandlerdefines the API forExtensionsthat wish to handle exceptions thrown during the execution of@BeforeAll,@BeforeEach,@AfterEach, and@AfterAlllifecycle methods.Common use cases include swallowing an exception if it's anticipated, logging errors, or rolling back a transaction in certain error scenarios.
Implementations of this extension API must be registered at the class level if exceptions thrown from
@BeforeAllor@AfterAllmethods are to be handled. When registered at the test level, only exceptions thrown from@BeforeEachor@AfterEachmethods will be handled.Constructor Requirements
Consult the documentation in
Extensionfor details on constructor requirements.Implementation Guidelines
An implementation of an exception handler method defined in this API must perform one of the following.
- Rethrow the supplied
Throwableas is, which is the default implementation. - Swallow the supplied
Throwable, thereby preventing propagation. - Throw a new exception, potentially wrapping the supplied
Throwable.
If the supplied
Throwableis swallowed by a handler method, subsequent handler methods for the same lifecycle will not be invoked; otherwise, the corresponding handler method of the next registeredLifecycleMethodExecutionExceptionHandler(if there is one) will be invoked with anyThrowablethrown by the previous handler.- Since:
- 5.5
- See Also:
TestExecutionExceptionHandler
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidhandleAfterAllMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable)Handle the suppliedThrowablethat was thrown during execution of a@AfterAlllifecycle method.default voidhandleAfterEachMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable)Handle the suppliedThrowablethat was thrown during execution of a@AfterEachlifecycle method.default voidhandleBeforeAllMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable)Handle the suppliedThrowablethat was thrown during execution of a@BeforeAlllifecycle method.default voidhandleBeforeEachMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable)Handle the suppliedThrowablethat was thrown during execution of a@BeforeEachlifecycle method.
-
-
-
Method Detail
-
handleBeforeAllMethodExecutionException
default void handleBeforeAllMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Handle the suppliedThrowablethat was thrown during execution of a@BeforeAlllifecycle method.Please refer to the class-level Javadoc for Implementation Guidelines.
- Parameters:
context- the current extension context; nevernullthrowable- theThrowableto handle; nevernull- Throws:
java.lang.Throwable
-
handleBeforeEachMethodExecutionException
default void handleBeforeEachMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Handle the suppliedThrowablethat was thrown during execution of a@BeforeEachlifecycle method.Please refer to the class-level Javadoc for Implementation Guidelines.
- Parameters:
context- the current extension context; nevernullthrowable- theThrowableto handle; nevernull- Throws:
java.lang.Throwable
-
handleAfterEachMethodExecutionException
default void handleAfterEachMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Handle the suppliedThrowablethat was thrown during execution of a@AfterEachlifecycle method.Please refer to the class-level Javadoc for Implementation Guidelines.
- Parameters:
context- the current extension context; nevernullthrowable- theThrowableto handle; nevernull- Throws:
java.lang.Throwable
-
handleAfterAllMethodExecutionException
default void handleAfterAllMethodExecutionException(ExtensionContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Handle the suppliedThrowablethat was thrown during execution of a@AfterAlllifecycle method.Please refer to the class-level Javadoc for Implementation Guidelines.
- Parameters:
context- the current extension context; nevernullthrowable- theThrowableto handle; nevernull- Throws:
java.lang.Throwable
-
-