Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRISOpens in a new window, see the InterSystems IRIS Migration Guide and Migrating to InterSystems IRIS, both available on the WRC Distributions pageOpens in a new window (login required).

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
Copy code to clipboard
FeedbackOpens in a new window