29. Errors, assertions and recovery
function run()
try
let result = 10 / 0
return result
catch problem
log(problem["message"])
return "Recovered"
end
endA runtime error stops the failing frame unless a surrounding try catches it. The caught dictionary includes message, line and scriptId. Use recovery for an expected failure, not to hide a typo in every line.
A shared action result with ok: false is promoted to a PCA runtime failure and can reach a catch block. An ordinary false or null return is not automatically an exception. Check the documented result and, where relevant, confirm the resulting game state.
assert condition is a statement that can fail the script. pca_assert(condition, message) is a diagnostic helper that reports and returns a Boolean; it does not have the same stop behavior.
script_error(text) logs an error message; it is not a throw statement.
Figure 10. Validate reports a source line and a useful explanation before you run the script.
try cannot repair a syntax error: invalid source never becomes a runnable program. Fix validation errors first, then use runtime logs or breakpoints to investigate behavior.
