Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Exceptions · Error Handling

Direct answer

Exceptions are errors raised by code that can be caught and handled, such as try/catch/finally in PowerShell and Python. Catch specific exceptions and include useful context in the message.

When to use this

Use this when handling exceptions in scripts.

First 30 seconds

1. Catch specific exceptions.

2. Add context (target, step).

3. Re-raise if not handled.

4. Log tracebacks.

5. Don't hide failures.

Operational verification

exception → handler → log/re-raise

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
automation exception handling
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformautomation exception handling · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when handling exceptions in scripts.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as ambiguous target identity, stale inputs, partial success, unsafe retry, permission drift and confusing tool completion with target-evidence of the actual state, choosing the cases most relevant to exception taxonomy, propagation, catch scope, cleanup/finally behavior and preserving original cause/traceback rather than swallowing failures.

Step 2 Common mistakes Narrow the fault
  • Catching all exceptions and continuing.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Catch specific exception types.
  • Add context to error messages.
  • Re-raise exceptions you cannot handle.
Key checks
  • try/except, try/catch, block/rescue usage — mechanisms
  • Specific exception types — precision
  • Context in error messages — diagnostics
ReferenceWhy it matters1 section · depth on demand

In depth

An exception is a language's way of signalling that something went wrong, interrupting normal flow until code catches and handles it. Handling exceptions well means catching specific errors where you can do something useful about them, and letting everything else stop the program with a clear message.

Common mistakes and better practice:

MistakeBetter
except: / catch {} catching everythingCatch specific exception types
Swallowing errors silentlyLog with context, then re-raise or handle
Losing the original errorChain it (raise ... from e)
Cleanup skipped on errorfinally or context managers
try:
    with ConnectHandler(**dev) as conn:
        out = conn.send_command("show version")
except NetmikoAuthenticationException:
    log.error("auth failed: %s", dev["host"]); raise
except NetmikoTimeoutException:
    log.warning("timeout: %s", dev["host"]); failed.append(dev["host"])
ReferenceImportant terms & boundaries1 section · depth on demand
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docautomation exception handling current

Authoritative/upstream documentation reviewed for bounded claims in Error Handling > Exceptions. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.python.org/3/tutorial/errors.html · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For exception taxonomy, propagation, catch scope, cleanup/finally behavior and preserving original cause/traceback rather than swallowing failures, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?