Top Description Methods
org.junit.jupiter.api.extension

public Interface TestExecutionExceptionHandler

extends Extension
Annotations
@FunctionalInterface
@API
status:STABLE
since:5.0
Static Imports
org.apiguardian.api.API.Status.STABLE

TestExecutionExceptionHandler defines the API for Extensions 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.

Constructor Requirements

Consult the documentation in Extension for details on constructor requirements.

Since
5.0
See Also
LifecycleMethodExecutionExceptionHandler

Method Summary

Modifier and TypeMethod and Description
public void
handleTestExecutionException(ExtensionContext
the current extension context; never null
context
,
Throwable
the Throwable to handle; never null
throwable
)

Handle the supplied throwable.

Method Detail

handleTestExecutionExceptionback to summary
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable

Handle the supplied throwable.

Implementors must perform one of the following.

  1. Swallow the supplied throwable, thereby preventing propagation.
  2. Rethrow the supplied throwable as is.
  3. Throw a new exception, potentially wrapping the supplied throwable.

If the supplied throwable is swallowed, subsequent TestExecutionExceptionHandlers will not be invoked; otherwise, the next registered TestExecutionExceptionHandler (if there is one) will be invoked with any Throwable thrown by this handler.

Note that the execution exception in the supplied ExtensionContext will not contain the Throwable thrown during invocation of the corresponding @Test method.

Parameters
context:ExtensionContext

the current extension context; never null

throwable:Throwable

the Throwable to handle; never null