Class TryCatchExecutor

java.lang.Object
ai.nervemind.app.executor.TryCatchExecutor
All Implemented Interfaces:
NodeExecutor

@Component public class TryCatchExecutor extends Object implements NodeExecutor
Executor for the "tryCatch" node type - provides structured error handling.

Wraps operations in try/catch/finally blocks for graceful error handling within workflows. Allows workflows to continue execution even when individual operations fail, and enables custom error recovery logic.

Node Parameters

TryCatch node configuration parameters
Parameter Type Default Description
tryOperations List [] Operations to execute in try block
catchOperations List [] Operations to execute on error
finallyOperations List [] Operations that always execute
errorVariable String "error" Variable name for error info
continueOnError Boolean true Continue workflow after error
logErrors Boolean true Log errors to console

Operation Structure

Each operation in tryOperations, catchOperations, or finallyOperations:

  • type - Node type to execute (e.g., "httpRequest")
  • name - Display name (optional)
  • config - Configuration for that node type

Execution Flow

  1. Execute tryOperations in sequence
  2. IF error occurs:
     - Store error info in [errorVariable]
     - Execute catchOperations
  3. ALWAYS execute finallyOperations
  4. Return combined output or throw if continueOnError=false

Error Information

When an error occurs, the following is stored in the error variable:

  • message - Error message string
  • type - Exception class name
  • timestamp - When error occurred
  • operation - Which operation failed

Output Data

Output keys added by this executor
Key Type Description
success Boolean True if try block completed without errors
hasError Boolean True if an error was caught
[errorVariable] Map Error information (if error occurred)
See Also:
  • Constructor Details

    • TryCatchExecutor

      public TryCatchExecutor(@Lazy NodeExecutorRegistry nodeExecutorRegistry)
      Creates a new try-catch executor.
      Parameters:
      nodeExecutorRegistry - the registry for accessing other node executors
  • Method Details

    • getNodeType

      public String getNodeType()
      Description copied from interface: NodeExecutor
      Unique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.
      Specified by:
      getNodeType in interface NodeExecutor
      Returns:
      The unique type string (e.g., "httpRequest", "llmChat").
    • execute

      public Map<String,Object> execute(ai.nervemind.common.domain.Node node, Map<String,Object> input, ExecutionService.ExecutionContext context)
      Description copied from interface: NodeExecutor
      Executes the business logic for this node type.
      Specified by:
      execute in interface NodeExecutor
      Parameters:
      node - The node definition containing parameters and configuration. Use Node.parameters() to access user settings.
      input - Combined output from all upstream nodes that connected to this node. For simple flows, this contains the direct predecessor's output. For merge nodes, it contains combined data.
      context - Verification context providing access to workflow-scoped services, logger, and execution metadata.
      Returns:
      A Map containing the results of this node's execution. Keys in this map become available variables for downstream nodes.
      Note: Returning null is treated as an empty map.