Skip to reading
PCA Script Programming

29. Errors, assertions and recovery

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView illustrations
Code example
function run()
    try
        let result = 10 / 0
        return result
    catch problem
        log(problem["message"])
        return "Recovered"
    end
end

A 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.

Page 37 of 357Permalink
Go to page