## 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
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

Name | Description
--- | ---
Continued | Specifies an expression that determines whether the exception is ignored and processing of the original route continues after the `onException` route completes.[a]
language | Specifies the expression language used to process the continued expression.
Retry While | Specifies an expression that determines if the message causing the exception should be redelivered. The message is redelivered until the expression evaluates to `false`.[a]
language | Specifies the expression language used to process the expression.
Handled | Specifies an expression that determines if the exception is marked as handled.[a]
language | Specifies the expression language used to process the expression.
Exceptions | Specifies 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 Handler | Specifies whether the node should use the error handler configured for the route. The default is `Disabled`.
Redelivery Policy Ref | Specifies a reference to bean defining the redelivery policy.
On Redelivery Ref | Specifies a reference to a custom processor for processing the message before it is redelivered.
Use Original Message Policy | Specifies 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 | Specifies how to handle failed deliveries. Redelivery options are listed in Table 41, “Redelivery Properties”.
Id | Specifies a unique identifier for the endpoint. The Id can be used to refer to the endpoint in the Camel XML file.
Description | Specifies 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

Name | Description
--- | ---
Async Delayed Redelivery | Specifies 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 Factor | Specifies 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 Pattern | Specifies 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 Redelivery | Specifies whether to disable the redelivery feature. Redelivery is enabled when Maximum Redeliveries is set to a positive number.
Log Continued | Specifies whether to log continuously reoccurring exceptions. The default is `false`.
Log Exhausted | Specifies whether to log all failed redelivery attempts. The default is `true`.
Log Handled | Specifies whether to log handled exceptions. The default is `false`.
Log Retry Attempted | Specifies whether to log redelivery attempts. The default is `true`.
Log Retry Stack Trace | Specifies whether to log stack traces for failed delivery attempts. The default is `false`.
Log Stack Trace | Specifies whether to include the JVM stack trace in the error logs. The default is `true`.
Maximum Redeliveries | Specifies the maximum number of delivery attempts. The default is `0`.
Maximum Redelivery Delay | Specifies, in milliseconds, the maximum redelivery delay when using an exponential back-off strategy. The default is `60 * 1000`.
Redelivery Delay | Specifies the delay, in milliseconds, between redelivery attempts. The default is `1000`.
Retries Exhausted Log Level | Specifies the logging level at which to log delivery failure. The default is `Error`.
Retry Attempted Log Level | Specifies the logging level at which to redelivery attempts. The default is `Debug`.
Use Collision Avoidance | Specifies 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 Off | Specifies whether to use exponential backoff. The default is `false`.

## Related topics

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