Files
clawdbot/extensions/open-prose/skills/prose/examples/22-error-handling.prose
2026-01-23 00:49:40 +00:00

52 lines
1.3 KiB
Plaintext

# Error Handling Example
# Demonstrates try/catch/finally patterns for resilient workflows
# Basic try/catch for error recovery
try:
session "Attempt to fetch data from external API"
catch:
session "API failed - use cached data instead"
# Catch with error variable for context-aware handling
try:
session "Parse and validate complex configuration file"
catch as err:
session "Handle the configuration error"
context: err
# Try/catch/finally for resource cleanup
try:
session "Open database connection and perform queries"
catch:
session "Log database error and notify admin"
finally:
session "Ensure database connection is properly closed"
# Nested error handling
try:
session "Start outer transaction"
try:
session "Perform risky inner operation"
catch:
session "Recover inner operation"
throw # Re-raise to outer handler
catch:
session "Handle re-raised error at outer level"
# Error handling in parallel blocks
parallel:
try:
session "Service A - might fail"
catch:
session "Fallback for Service A"
try:
session "Service B - might fail"
catch:
session "Fallback for Service B"
session "Continue with whatever results we got"
# Throwing custom errors
session "Validate input data"
throw "Validation failed: missing required fields"