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 42 describes the properties you can specify using the properties editor.

Table 42. On Exception Properties

NameDescription
ExceptionSpecifies 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.
LanguageSpecifies the expression language used to process the continued expression.
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.
LanguageSpecifies the expression language used to process the expression.
Id

Specifies a unique identifier for the endpoint.

The tooling automatically generates an id for a node when it is created, but you can remove that id or replace it with your own. The Camel debugger requires all nodes with a breakpoint set to have a unique id.

You can use the id to refer to endpoints in your Camel XML file.

On Exception Occurred RefSpecifies a reference to a processor that should be processed just after an exception occured.
On Redelivery RefSpecifies a reference to a custom processor for processing the message before it is redelivered.
On WhenSets an additional logic that should be true before the OnException is triggered. It is used for fine grained controlling whether a thrown exception should be intercepted by this exception type or not.
Redelivery PolicySpecifies how to handle failed deliveries. Redelivery options are listed in Table 43, “Redelivery Properties”.
Redelivery Policy RefSpecifies a reference to bean defining the redelivery policy.
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 Policy

Table 43 describes the properties for configuring the redelivery policy.

Table 43. Redelivery Properties

NameDescription
Allow Redelivery While Stopping

Specifies whether to allow redelivery while a route that uses error handling shuts down.

When enabled, the route attempts redelivery of inflight messages during shutdown.

When disabled, no attempts to redeliver are made, resulting in the failure of inflight messages and the cessation of message processing.

The default is Disabled.

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 Disabled.
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