Pcornel
Automation · Scripting

Exceptions

Cheat sheet · https://pcornel.dk/topic.php?topic=5222

Back to the Topic

Answer

Exceptions represent abnormal execution paths that interrupt normal control flow. Reliable scripting catches only where recovery or context can be added, preserves cause and never treats handled as resolved automatically.

Remember

  • Exception caught ≠ error resolved; catch blocks can hide an unresolved target failure.
  • Retry after exception ≠ safe automatically; side effects may have partially completed before the error surfaced.
  • Generic catch-all ≠ resilience; broad handlers can suppress defects and destroy useful stack/context.
  • Cleanup failure ≠ original failure automatically; both may need to be preserved when finalization also fails.

First checks

  • try { … } catch { … } — PowerShell
  • try/except in Python — exceptions
  • trap 'cleanup' ERR EXIT — Bash cleanup

Verify in this order

error → exception → handle/cleanup → exit code

Where it usually breaks

A caught exception proves only that code intercepted a failure signal; it does not prove the failed operation was undone, retried safely or resolved.

Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.

Exceptions scripting boundary map

BoundaryHealthy evidenceSuspicious evidence
Input / runtimeEffective inputs, runtime, working context and dependency versions are explicitHidden defaults, stale environment, wrong interpreter/path or unvalidated input
Logic / executionBranch/function/module decisions and external actions expose per-operation resultsSwallowed failures, shell reinterpretation, blind retries or last-result-wins behavior
Result / proofExit/exception/log evidence is correlated with independent target read-backProcess success or printed output treated as target success
Recovery / troubleshootingFirst failed boundary is preserved, changed minimally and retestedRandom edits, catch-all suppression or evidence destroyed before diagnosis

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5222

Confirmation

Confirm action

Continue?