Package org.axonframework.messaging.core
Class HandlerExecutionException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.axonframework.common.AxonException
org.axonframework.messaging.core.HandlerExecutionException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CommandExecutionException,QueryExecutionException
Base exception for exceptions raised by Handler methods. Besides standard exception information (such as message and
cause), these exception may optionally carry an object with additional application-specific details about the
exception.
By default, a stack trace is not generated for this exception. However, the stack trace creation can be enforced
explicitly via the constructor accepting the
writableStackTrace parameter.
When these details cross an infrastructure boundary (for example, a remote command or query dispatched through Axon
Server), they may arrive as raw data alongside a Converter rather than as the original application object. In
that case, getDetails(Class), getDetails(TypeReference), and getDetails(Type) apply the
Converter lazily, on request, mirroring how Message.payloadAs(Class) defers payload conversion. This
keeps the thrower and the receiver decoupled from having to agree on the exact same details class or version.- Since:
- 4.2.0
- Author:
- Allard Buize
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHandlerExecutionException(String message) Initializes an execution exception with givenmessage.HandlerExecutionException(String message, @Nullable Throwable cause) Initializes an execution exception with givenmessageandcause.HandlerExecutionException(String message, @Nullable Throwable cause, @Nullable Object details) Initializes an execution exception with givenmessage,causeand application-specificdetails.HandlerExecutionException(String message, @Nullable Throwable cause, @Nullable Object details, boolean writableStackTrace) Initializes an execution exception with givenmessage,cause, application-specificdetails, andwritableStackTraceHandlerExecutionException(String message, @Nullable Throwable cause, @Nullable Object details, @Nullable Converter converter, boolean writableStackTrace) Initializes an execution exception with givenmessage,cause, application-specificdetails,converter, andwritableStackTrace. -
Method Summary
Modifier and TypeMethodDescription<R> Optional<R> Deprecated, for removal: This API element is subject to removal in a future version.<R> Optional<R> getDetails(Class<R> type) Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using theConverterattached to this exception (if any).<R> Optional<R> getDetails(Class<R> type, @Nullable Converter converter) Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using the givenconverter.<R> Optional<R> getDetails(Type type) Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using theConverterattached to this exception (if any).<R> Optional<R> getDetails(Type type, @Nullable Converter converter) Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using the givenconverter.<R> Optional<R> getDetails(TypeReference<R> type) Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using theConverterattached to this exception (if any).<R> Optional<R> getDetails(TypeReference<R> type, @Nullable Converter converter) Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using the givenconverter.static <R> Optional<R> resolveDetails(@Nullable Throwable throwable) Resolve details from the giventhrowable, taking into account that the details may be available in any of theHandlerExecutionExceptionsin the "cause" chain.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
HandlerExecutionException
Initializes an execution exception with givenmessage. The cause and application-specific details are set tonull.- Parameters:
message- a message describing the exception
-
HandlerExecutionException
Initializes an execution exception with givenmessageandcause. Application-specific details and theirConverter, if any, are inherited from the firstHandlerExecutionExceptionin thecausechain that carries details.- Parameters:
message- a message describing the exceptioncause- the cause of the execution exception
-
HandlerExecutionException
public HandlerExecutionException(String message, @Nullable Throwable cause, @Nullable Object details) Initializes an execution exception with givenmessage,causeand application-specificdetails.- Parameters:
message- a message describing the exceptioncause- the cause of the execution exceptiondetails- an object providing application-specific details of the exception
-
HandlerExecutionException
public HandlerExecutionException(String message, @Nullable Throwable cause, @Nullable Object details, boolean writableStackTrace) Initializes an execution exception with givenmessage,cause, application-specificdetails, andwritableStackTrace- Parameters:
message- a message describing the exceptioncause- the cause of the execution exceptiondetails- an object providing application-specific details of the exceptionwritableStackTrace- whether the stack trace should be generated (true) or not (false)
-
HandlerExecutionException
@Internal public HandlerExecutionException(String message, @Nullable Throwable cause, @Nullable Object details, @Nullable Converter converter, boolean writableStackTrace) Initializes an execution exception with givenmessage,cause, application-specificdetails,converter, andwritableStackTrace. This constructor is used by messaging infrastructure to attach aConverterwhen reconstructingdetailsfrom raw data received over an infrastructure boundary (for example, a remote command or query response). It is not meant to be used directly by application code, which typically already has the details object in its final form and can useHandlerExecutionException(String, Throwable, Object)instead.- Parameters:
message- a message describing the exceptioncause- the cause of the execution exceptiondetails- an object providing application-specific details of the exception, potentially raw data awaiting conversionconverter- theConverterto lazily apply whengetDetails(Class),getDetails(TypeReference), orgetDetails(Type)is called with a typedetailsdoes not already match, ornullif no such conversion is availablewritableStackTrace- whether the stack trace should be generated (true) or not (false)
-
-
Method Details
-
resolveDetails
Resolve details from the giventhrowable, taking into account that the details may be available in any of theHandlerExecutionExceptionsin the "cause" chain.- Type Parameters:
R- the type of details expected- Parameters:
throwable- the exception to resolve the details from- Returns:
- an
Optionalcontaining details, if present in the giventhrowable
-
getDetails
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofgetDetails(Class), or any of theType,TypeReference, orConverterparameter combinations, as those ensure the details are converted to the desired typeReturns anOptionalcontaining application-specific details of the exception, if any were provided.These details are implicitly cast to the expected type. A mismatch in type may lead to a
ClassCastExceptionfurther downstream, when accessing theOptional'senclosed value.- Type Parameters:
R- the type of details expected- Returns:
- an Optional containing the details, if provided
-
getDetails
Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using theConverterattached to this exception (if any).- Type Parameters:
R- the type of details expected- Parameters:
type- the type to return the details as- Returns:
- an
Optionalcontaining the details converted totype, if provided - Throws:
ConversionException- if the details are present but do not matchtype, and either noConverteris available or the conversion fails
-
getDetails
Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using the givenconverter. If the current details already are an instance oftype, no conversion takes place and the givenconverteris ignored. Otherwise, the givenconverteris used to convert the details intotype. This allows the thrower and the receiver of these details to use different classes or versions for the same logical details.- Type Parameters:
R- the type of details expected- Parameters:
type- the type to return the details asconverter- the converter to convert the details with, ornullif no conversion is available- Returns:
- an
Optionalcontaining the details converted totype, if provided - Throws:
ConversionException- if the details are present but do not matchtype, and either noconverteris given or the conversion fails
-
getDetails
Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using theConverterattached to this exception (if any). Behaves identically togetDetails(Class), but supports generic types (for exampleList<String>) through aTypeReference.- Type Parameters:
R- the type of details expected- Parameters:
type- the type to return the details as- Returns:
- an
Optionalcontaining the details converted totype, if provided - Throws:
ConversionException- if the details are present but do not matchtype, and either noConverteris available or the conversion fails
-
getDetails
Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using the givenconverter. Behaves identically togetDetails(Class, Converter), but supports generic types (for exampleList<String>) through aTypeReference.- Type Parameters:
R- the type of details expected- Parameters:
type- the type to return the details asconverter- the converter to convert the details with, ornullif no conversion is available- Returns:
- an
Optionalcontaining the details converted totype, if provided - Throws:
ConversionException- if the details are present but do not matchtype, and either noconverteris given or the conversion fails
-
getDetails
Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using theConverterattached to this exception (if any). Behaves identically togetDetails(Class), but accepts a rawType, for callers that already have one at hand (for example, obtained through reflection) instead of aClassorTypeReference.- Type Parameters:
R- the type of details expected- Parameters:
type- the type to return the details as- Returns:
- an
Optionalcontaining the details converted totype, if provided - Throws:
ConversionException- if the details are present but do not matchtype, and either noConverteris available or the conversion fails
-
getDetails
Returns anOptionalcontaining application-specific details of the exception, converted into the giventypeif necessary, using the givenconverter. If the current details already are an instance oftype, no conversion takes place and the givenconverteris ignored. Otherwise, the givenconverteris used to convert the details intotype. This allows the thrower and the receiver of these details to use different classes or versions for the same logical details. This is the terminal operation every othergetDetailsoverload delegates to.- Type Parameters:
R- the type of details expected- Parameters:
type- the type to return the details asconverter- the converter to convert the details with, ornullif no conversion is available- Returns:
- an
Optionalcontaining the details converted totype, if provided - Throws:
ConversionException- if the details are present but do not matchtype, and either noconverteris given or the conversion fails
-
getDetails(Class), or any of theType,TypeReference, orConverterparameter combinations, as those ensure the details are converted to the desired type