Skip to main content

Try, Catch, and Throw Commands

You use the Try/Catch construct to monitor a block of code (within Try) for errors at runtime, and when an error occurs, raise an exception and transfer execution to another block of code (within Catch) to handle the error. Use the Throw command to explicitly raise an exception. You'd typically do this inside a Catch block, to transfer execution to a higher level enclosing Catch. Inside Catch, the $Zerror system variable contains error information.


Both Catch and Throw have an exception argument, which is an object containing information about the exception. Working with objects in Caché is covered briefly later on, but the details of Caché exception objects are beyond the scope of this tutorial.

SAMPLES>try {write "hello", 1/0} catch {write !,"A ", $zerror, " error occurred"}
A <DIVIDE> error occurred
FeedbackOpens in a new tab