Appendix: Error Handling
You can't always predict when something will go wrong with your expressions, but you can minimise the impact of unwanted situations by creating contingency plans. That way, rather than facing an incomprehensible error message that gives no clue of what went wrong, developers and end users alike can be given meaningful feedback to help them understand and potentially fix the problem. Preparing your expressions in this manner is known as Error Handling.
Applications such as KnowledgeKube typically include a level of error handling known as Platform-Level Error Handling. The remainder of this topic discusses bespoke error handling - also known as User-Defined Error Handling.
To enable user-defined error handling in a particular expression, you need to include a statement that calls a special function known as OnErrorJumpTo. Once executed, this statement will persist for the remainder of the expression's run-time. If at any point an error is raised the statement will execute a labelled statement, much like a regular JumpTo statement. The named block in this type of scenario will typically be a means of lessening the error's impact, such as presenting a meaningful error message that explains what went wrong, and what the end user should do next.
In addition to redirecting the flow of an expression, the OnErrorJumpTo function can make use of optional parameters that enable detailed reporting of the error.
KnowledgeKube provides another function named RaiseError, which lets you deliberately trigger an error, even if there's nothing wrong as far as the platform-level error handler is concerned. This function is an integral part of user-defined error handling, as it lets you create custom 'fail' conditions for your applications.