Documentation

try

Catch pipeline errors

try

The try action provides error handling for pipelines by catching errors that occur during execution and allowing graceful recovery. It executes a pipeline and, if any errors occur, executes the catch block instead of propagating the error.

Syntax

try [pipeline directive] {
    # Main pipeline - may produce errors
    main-actions...
} catch {
    # Execute this pipeline if an error occurs in the main pipeline
    error-handling-actions...
}

Parameters

  • pipeline directive (optional): Pipeline directive for the main block. Defaults to while
  • main pipeline: Actions that may produce errors
  • catch pipeline: Actions executed when an error occurs in the main pipeline

Behavior

The try block monitors the execution of the main pipeline:

  • Success: If the main pipeline completes without errors, its result is returned and the catch block is not executed
  • Error: If any action in the main pipeline produces an error, execution stops and the catch block is executed instead
  • Non-error results: Results like reject, accept, or ignore are not considered errors and will not trigger the catch block

Pipeline Directive

The pipeline directive does not affect error handling; it only controls how the main pipeline processes non-error results. Same behavior can be accomplished by combining with the standalone pipeline directive actions. These two are equivalent:

try first {
    backend "PRIMARY_AUTH";
    backend "SECONDARY_AUTH";
} catch {
    # Error handling...
}
try {
  first {
    backend "PRIMARY_AUTH";
    backend "SECONDARY_AUTH";
  }
} catch {
    # Error handling...
}

Error Information

When an error is caught, the error message is made available in the aaa.caught_error variable within the catch block. This variable is automatically cleared after the try block completes.

Examples

Basic Error Handling

try {
    backend "PRIMARY_AUTH";
    backend "SECONDARY_AUTH";
} catch {
    reject "operation failed: %{aaa.caught_error}";
}

accept "authentication succeeded";