Catch a failed operation in PCA Script
LANGUAGE GUIDE · PCA SCRIPT
Use try around the operation that can fail. Catch receives an error record. Keep the block small enough that the message points to one job.
function run()
let count = -1
try
assert count >= 0
return "Ready"
catch problem
log problem.message
return "Check the count"
end
endIn this listing the count is deliberately fixed at −1 so the failure is visible. The assertion fails. The catch block logs Assertion failed. and returns Check the count. A nonnegative count reaches the earlier return.
| problem.message | A readable description of the failure. |
|---|---|
| problem.line | The source line reported for that failure. |
| problem.scriptId | The ID of the record that reported the error. |
A syntax error prevents this routine from starting. Fix it with Validate. Use catch for a runtime failure reported through the shared script engine. If an operation returns a failure value normally, inspect that value explicitly.
