Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Safe Error Handling (Try / Otherwise)
Safely capture and handle runtime errors without terminating execution.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Control Flow). Copy the parameterized template or run the self-contained example.
- 1Category: Control Flow
- 2Attribution: Otter Core Language Spec (D23, D68)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
try
${riskyOperation}
otherwise into ${reason}
say "Error encountered:" ${reason}
.
caught is false
reasonMsg is ""
try
badMath is 10 divided by 0
say badMath
otherwise into reason
caught is true
reasonMsg is reason
say "Handled error safely:" reason
.
if caught is not true
fail with "try-otherwise failed: exception was not caught"
.
Installation & Usage
otter snippet inspect cf-try-otherwise
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.