PADFoundationerror-handlingtry-catchresiliencefoundationblockexception

Error Handler Wrapper

A structured BLOCK/ON ERROR pattern that catches exceptions, logs the error details, increments the error counter, and optionally rethrows. Drop this around any risky action group - file I/O, web calls, Excel operations - for consistent error handling across your flow.

0 copies

Section 1: Configure Error Context

PAD Script
1**REGION Configure Error Context
2SET strStepName TO $'''REPLACE_WITH_STEP_NAME'''
3SET boolRethrow TO False
4SET boolStepSuccess TO True
5SET strErrorMessage TO $'''(none)'''
6SET numErrorCount TO 0
7**ENDREGION

Section 2: Protected Block with Error Handling

PAD Script
1**REGION Protected Block with Error Handling
2BLOCK ErrorHandler
3ON BLOCK ERROR REPEAT 1 TIMES WAIT 2
4ON BLOCK ERROR
5 SET boolStepSuccess TO False
6 SET strErrorMessage TO $'''[%strStepName%] %LastError%'''
7 SET numErrorCount TO numErrorCount + 1
8 DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> dtErrorTime
9 Text.ConvertDateTimeToText.FromCustomDateTime DateTime: dtErrorTime CustomFormat: $'''yyyy-MM-dd HH:mm:ss''' Result=> strErrorTimestamp
10 IF boolRethrow = True THEN
11 THROW ERROR
12 END
13END
14 /# ── Place your risky action(s) here ── #/
15 SET boolStepSuccess TO True
16END
17**ENDREGION

Usage Notes

  • Replace REPLACE_WITH_STEP_NAME with a descriptive label for the action group being protected (e.g., $'''Excel File Save''')
  • Place all risky actions inside the BLOCK ErrorHandler where the comment marks the insertion point
  • The ON BLOCK ERROR REPEAT 1 TIMES WAIT 2 line provides one automatic retry with a 2-second delay before the error handler fires
  • Set boolRethrow to True if you want the error to propagate up to the parent flow after logging; leave as False to swallow the error and continue
  • strErrorMessage captures a formatted error string with the step name prefix — use it for logging or notification
  • numErrorCount increments on each error — check this counter at flow end to determine overall success/failure
  • strErrorTimestamp records when the error occurred for audit trail purposes
  • Wrap each major section of your flow (file operations, API calls, Excel work) in its own Error Handler Wrapper with a unique strStepName
  • Combine with Retry With Backoff for nested resilience: retry inside the block, then catch with this wrapper if all retries fail

Requirements

  • No external dependencies — uses only built-in PAD block, error handling, and DateTime actions
  • LastError is a built-in PAD object automatically available inside ON BLOCK ERROR handlers
  • numErrorCount should be initialized by Variable Bootstrap if used across the full flow; Section 1 provides a local fallback
  • DateTime action must be available for timestamp capture (included in all PAD versions)
  • For rethrow behavior, the parent flow or calling subflow must have its own error handler to catch the propagated error