You can choose which exceptions you want to handle, by type, or handle all exceptions with the same code. To handle an exception means that you do not allow the current program to terminate, but provide special processing for the error. Additionally, you can trigger your own exceptions, using the EGL throw statement, either to cause an existing exception to propagate or to alert the user to an error that your program has discovered on its own. See throw.
The mechanism that EGL uses to handle errors is the try block (see try). Any statement that throws an exception inside a try block causes the program to look for a matching onException block within that same try block. If an onException block exists that references the exception thrown, control passes to the code within that block.
Exceptions do not propagate out of remotely called programs or service calls. If a remotely called program ends due to an error, you get an InvocationException. If a service call ends due to an error, you get a ServiceInvocationException. Both types contain the original error description. The InvocationException also contains the returnValue and errno from the called program, if available.
Exceptions propagate normally out of locally called programs.
You can also use an older method of exception handling; see Using V6 exception compatibility.
EGL provides a series of system exceptions to indicate the specific nature of a runtime problem. Each of these exceptions is a record with the Exception stereotype (see The Exception stereotype) from which you can retrieve information. The onException block uses this record type to catch a particular exception.
if (userRequest = "A") try add record1; onException(ex1 FileIOException) myErrorHandler(1); onException(ex2 RuntimeException) myErrorHandler(2); onException(ex3 SQLException) myErrorHandler(3); onException(ex4 AnyException) myErrorHandler(4); end // try end // if
For details on system exceptions, see EGL core Exception records.