Try, Catch, Finally, and Throw
Exceptions describe recoverable runtime failures. Use structured Control blocks to handle them.
Build a handler
Section titled “Build a handler”- Choose Control → Try and put the protected body inside its brackets.
- Follow it with typed Catch blocks.
- Configure each Catch with a Private, non-null Throwable/Exception-compatible Variable.
- Put more specific exception types before broader ones.
- Add Finally for cleanup that must run regardless of the result.
Try Body: operation that may failCatch: Private Exception error Body: show or record a useful failure messageFinally Body: restore temporary round stateTo replace a structured Control with an ordinary operation, remove and replace it explicitly; its nested body should not be silently discarded.
Throwable and custom exceptions
Section titled “Throwable and custom exceptions”Exception extends Throwable. A custom instance class may extend Exception. Managed fields include message, nullable cause, and a generated stack String. Throw requires a non-null Throwable-compatible object.
Native operation failures become Exceptions. Throw does not mean sending a Minecraft projectile; it raises the configured failure object through the task’s handlers.
Propagation
Section titled “Propagation”An awaited method failure can be caught by the caller. An unhandled failure stops its own task, reports source/build/call-stack information, and leaves unrelated tasks running. A detached method does not propagate its error back as an awaited result.
Finally behavior
Section titled “Finally behavior”Finally runs after normal completion, errors, returns, Break, and Continue. A normal Finally may suspend. Cancellation permits only bounded cleanup with no suspension or new tasks.
Resource failures such as heap/task/frame limits, execution budgets, and regex work limits are fatal. Catch cannot intercept them, and Finally cannot suppress them. Design bounded work rather than using Try/Catch to attempt an unlimited loop.
Diagnose the original cause
Section titled “Diagnose the original cause”Use /plot diagnostics and /plot diagnostics error to locate a reported failure. Preserve useful context rather than catching everything and silently ignoring it. When the draft differs from the failing build, inspect the revision before editing the wrong block.