public class ExceptionUtils extends Object
| Constructor and Description |
|---|
ExceptionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsType(Throwable throwable,
Class<?> type)
This method returns true if the throwable contains a
Throwable that matches the specified class or subclass in the
exception chain. |
static Event |
createErrorEvent(Event currentEvent,
Object annotatedObject,
MessagingException messagingException,
ErrorTypeLocator errorTypeLocator)
Create new
Event with Error instance set. |
static Optional<Throwable> |
extractCauseOfType(Throwable throwable,
Class<? extends Throwable> throwableType)
|
static Optional<org.mule.runtime.api.connection.ConnectionException> |
extractConnectionException(Throwable throwable)
|
static <T extends Throwable> |
extractOfType(Throwable throwable,
Class<T> throwableType)
|
static <ET> ET |
getDeepestOccurrenceOfType(Throwable throwable,
Class<ET> type)
This method returns the throwable closest to the root cause that matches the specified class or subclass.
|
static org.mule.runtime.api.message.Error |
getErrorFromFailingProcessor(Object annotatedObject,
Throwable causeException,
ErrorTypeLocator errorTypeLocator) |
static org.mule.runtime.api.message.ErrorType |
getErrorTypeFromFailingProcessor(Object annotatedObject,
Throwable exception,
ErrorTypeLocator errorTypeLocator)
Determine the
ErrorType of a given exception thrown by a given message processor. |
static String |
getFullStackTraceWithoutMessages(Throwable throwable)
Similar to
ExceptionUtils.getFullStackTrace(Throwable) but removing the exception and causes messages. |
static Throwable |
getRootCauseException(Throwable exception)
Resolve the root cause of an exception.
|
static MessagingException |
putContext(MessagingException messagingException,
Processor failingMessageProcessor,
Event event,
FlowConstruct flowConstruct,
MuleContext muleContext) |
static <T,E extends Exception> |
tryExpecting(Class<E> expectedExceptionType,
Callable<T> callable,
ExceptionHandler<T,E> exceptionHandler)
|
static MessagingException |
updateMessagingException(org.slf4j.Logger logger,
Processor processor,
MessagingException exception,
ErrorTypeLocator errorTypeLocator,
ErrorTypeRepository errorTypeRepository,
FlowConstruct flowConstruct,
MuleContext muleContext)
Updates the
MessagingException to be thrown based on the content of the exception parameter and the chain of
causes inside it. |
static MessagingException |
updateMessagingExceptionWithError(MessagingException exception,
Processor failing,
FlowConstruct flowConstruct) |
public static boolean containsType(Throwable throwable, Class<?> type)
Throwable that matches the specified class or subclass in the
exception chain. Subclasses of the specified class do match.throwable - the throwable to inspect, may be nulltype - the type to search for, subclasses match, null returns falsepublic static <ET> ET getDeepestOccurrenceOfType(Throwable throwable, Class<ET> type)
throwable - the throwable to inspect, may be nulltype - the type to search for, subclasses match, null returns nullpublic static String getFullStackTraceWithoutMessages(Throwable throwable)
ExceptionUtils.getFullStackTrace(Throwable) but removing the exception and causes messages. This is useful to determine
if two exceptions have matching stack traces regardless of the messages which may contain invokation specific datathrowable - the throwable to inspect, may be nullnullpublic static Optional<org.mule.runtime.api.connection.ConnectionException> extractConnectionException(Throwable throwable)
Throwable parameter to obtain the first Throwable of type ConnectionException in the
exception chain.throwable - the last throwable in the exception chain.Optional value with the first ConnectionException in the exception chain if any.public static Optional<Throwable> extractCauseOfType(Throwable throwable, Class<? extends Throwable> throwableType)
Throwable parameter to obtain the first Throwable of type throwableType in the
exception chain and return the cause of it.throwable - the last throwable on the exception chain.throwableType - the type of the throwable that the cause is wanted.Throwable of type throwableType.public static <T extends Throwable> Optional<T> extractOfType(Throwable throwable, Class<T> throwableType)
Throwable parameter to obtain the first Throwable of type throwableType in the
exception chain.
This method handles recursive cause structures that might otherwise cause infinite loops. If the throwable parameter is a
ConnectionException the same value will be returned. If the throwable parameter has a cause of itself, then an empty
value will be returned.
throwable - the last throwable on the exception chain.throwableType - the type of the throwable is wanted to find.Throwable of type throwableType.public static <T,E extends Exception> T tryExpecting(Class<E> expectedExceptionType, Callable<T> callable, ExceptionHandler<T,E> exceptionHandler) throws E extends Exception
callable knowing that it might throw an Exception of type expectedExceptionType.
If that happens, then it will re throw such exception.
If the callable throws a RuntimeException of a different type, then it is also re-thrown. Finally, if an
exception of any different type is thrown, then it is handled by delegating into the exceptionHandler, which might in
turn also throw an exception or handle it returning a value.
T - the generic type of the return valueE - the generic type of the expected exceptionexpectedExceptionType - the type of exception which is expected to be throwncallable - the delegate to be executedexceptionHandler - a ExceptionHandler in case an unexpected exception is found insteadcallable or the exceptionHandlerE - if the expected exception is actually thrownE extends Exceptionpublic static org.mule.runtime.api.message.ErrorType getErrorTypeFromFailingProcessor(Object annotatedObject, Throwable exception, ErrorTypeLocator errorTypeLocator)
ErrorType of a given exception thrown by a given message processor.annotatedObject - the component that threw the exception.exception - the exception thrown.errorTypeLocator - the ErrorTypeLocator.ErrorTypepublic static MessagingException putContext(MessagingException messagingException, Processor failingMessageProcessor, Event event, FlowConstruct flowConstruct, MuleContext muleContext)
public static Event createErrorEvent(Event currentEvent, Object annotatedObject, MessagingException messagingException, ErrorTypeLocator errorTypeLocator)
Event with Error instance set.currentEvent - event when error occured.annotatedObject - message processor/source.messagingException - messaging exception.errorTypeLocator - the mule context.Event with relevant Error set.public static MessagingException updateMessagingException(org.slf4j.Logger logger, Processor processor, MessagingException exception, ErrorTypeLocator errorTypeLocator, ErrorTypeRepository errorTypeRepository, FlowConstruct flowConstruct, MuleContext muleContext)
MessagingException to be thrown based on the content of the exception parameter and the chain of
causes inside it.logger - instance to use for loggingprocessor - the failing processorexception - the exception to update based on it's contenterrorTypeLocator - the error type locatorerrorTypeRepository - the error type repositoryflowConstruct - the flow associated with the exceptionmuleContext - the context of the artifactMessagingException with the proper Error associated to it's Eventpublic static org.mule.runtime.api.message.Error getErrorFromFailingProcessor(Object annotatedObject, Throwable causeException, ErrorTypeLocator errorTypeLocator)
public static Throwable getRootCauseException(Throwable exception)
ErrorMessageAwareException then it's root
cause is used, else the candidate exception instance if returned.exception - candidate exception.public static MessagingException updateMessagingExceptionWithError(MessagingException exception, Processor failing, FlowConstruct flowConstruct)
Copyright © 2003–2017 MuleSoft, Inc.. All rights reserved.