Name

On Exception — Route to be executed when an exception is thrown

Usage

The On Exception pattern defines a set of steps that are executed when an exception is thrown. It can be scoped either locally to a specific route or globally to all routes defined in the context.

[Important]Important

Locally scoped On Exception patterns take precedent over globally scoped ones. Therefore, the globally scoped pattern will not be executed when a locally scoped On Exception exists.

When specifying a locally scoped On Exception pattern, the pattern directly follows the from endpoint in the route.

When specifying a globally scoped On Exception, the pattern starts a new route.

Properties

Table 40 describes the properties you can specify using the properties editor.

Table 40. On Exception Properties

NameDescription
ContinuedSpecifies an expression that determines whether the exception is ignored and processing of the original route continues after the onException route completes.[a]
languageSpecifies the expression language used to process the continued expression.
Retry WhileSpecifies an expression that determines if the message causing the exception should be redelivered. The message is redelivered until the expression evaluates to false.[a]
languageSpecifies the expression language used to process the expression.
HandledSpecifies an expression that determines if the exception is marked as handled.[a]
languageSpecifies the expression language used to process the expression.
ExceptionsSpecifies the list of exceptions the node handles. The Add button adds an entry typed in the field. The Delete button removes the selected entry from the list.
Inherit Error HandlerSpecifies whether the node should use the error handler configured for the route. The default is Disabled.
Redelivery Policy RefSpecifies a reference to bean defining the redelivery policy.
On Redelivery RefSpecifies a reference to a custom processor for processing the message before it is redelivered.
Use Original Message PolicySpecifies whether the message that began the route is placed in the dead letter queue instead of the message that caused the exception. The default is Disabled.
Redelivery PolicySpecifies how to handle failed deliveries. Redelivery options are listed in Table 41, “Redelivery Properties”.
IdSpecifies a unique identifier for the endpoint. The Id can be used to refer to the endpoint in the Camel XML file.
DescriptionSpecifies a text description for the node. This description is included in the generated XML file, but it is informational only. It is not used by Apache Camel.

[a] The expression is treated as returning a boolean. If the expression evaluates to a non-boolean value other than null it is evaluated as returning true.


Redelivery Policy

Table 41 describes the properties for configuring the redelivery policy.

Table 41. Redelivery Properties

NameDescription
Async Delayed RedeliverySpecifies whether asynchronous delayed redelivery is used to scheduled redelivers at a later time. When enabled, an asynchronous thread, rather than the current thread, performs redelivery. This ensures that no thread is blocked waiting for a redelivery. The default is false.
Back Off Multiplier

Specifies the multiplier used to determine the redelivery delay if exponential back-off is enabled. If m is the back-off multiplier and d is the redelivery delay, the sequence of redelivery attempts are then timed as follows:

d, m*d, m*m*d, m*m*m*d, ...

The default is 2.

Collision Avoidance FactorSpecifies a factor that is used to randomly tweak the redelivery delay if collision avoidance is enabled. The collision avoidance policy tweaks the next delay by a random amount, up to plus/minus p% of its current value. The default is 0.15.
Delay PatternSpecifies a pattern to use for calculating the delay, which enables you to specify fixed delays for interval groups. For example, the pattern 0:1000; 5:5000; 10:30000 specifies a 1 second delay between redelivery attempts 0 through 4, a 5 second delay between attempts 5 through 9, and a 30 second delay between all subsequent attempts.
Disable RedeliverySpecifies whether to disable the redelivery feature. Redelivery is enabled when Maximum Redeliveries is set to a positive number.
Log ContinuedSpecifies whether to log continuously reoccurring exceptions. The default is false.
Log ExhaustedSpecifies whether to log all failed redelivery attempts. The default is true.
Log HandledSpecifies whether to log handled exceptions. The default is false.
Log Retry AttemptedSpecifies whether to log redelivery attempts. The default is true.
Log Retry Stack TraceSpecifies whether to log stack traces for failed delivery attempts. The default is false.
Log Stack TraceSpecifies whether to include the JVM stack trace in the error logs. The default is true.
Maximum RedeliveriesSpecifies the maximum number of delivery attempts. The default is 0.
Maximum Redelivery DelaySpecifies, in milliseconds, the maximum redelivery delay when using an exponential back-off strategy. The default is 60 * 1000.
Redelivery DelaySpecifies the delay, in milliseconds, between redelivery attempts. The default is 1000.
Retries Exhausted Log LevelSpecifies the logging level at which to log delivery failure. The default is Error.
Retry Attempted Log LevelSpecifies the logging level at which to redelivery attempts. The default is Debug.
Use Collision AvoidanceSpecifies whether to use collision avoidance, which adds some randomization to the back-off timings, reducing the probability of contention. The default is false
Use Exponential Back OffSpecifies whether to use exponential backoff. The default is false.

Related topics

Expression and Predicates Languages
Adding beans and configuration
Configuring the route editor