Error trapping in Dyalog APL forms

An application's GUI looks like a Form with stuff on it. So it is appealing to describe it that way. That is to say, to define the GUI as a class derived from a Dyalog native Form.

Usage is trivial:. The  method is enough to keep the   instance in existence until the   button is clicked. Then everything disappears: no objects left, no clean-up to do.

This is an appealing way to code a GUI because of the high degree of encapsulation. Everything the application's GUI needs is contained in the Form. It doesn't even require a name assigned to it.

However, trapping such an application requires a little thought. If your error traps have relied on knowing the names of forms and so on, you will find them difficult to use here.

Let's make the reasonable assumption an error might occur elsewhere in the active workspace, not necessarily in a method of. Let's suppose that in the event of an error or an interrupt we want to (a) log the event and local environment, and (b) cut back and either restart or resume the application.

One thing we can't do is cut back the stack so far that 's methods are no longer on it. For example, let's insert a domain error into :

start it, and push the button.

You might think that you could set  to cut back to the instance and resume, by writing:

either in the class script or in its constructor. But it turns out that  is set in the workspace root, not in the object. When the trap fires, the stack is cut back to immediate execution, and the  instance vanishes.

A more robust approach overrides the  method   inherited from the   class. We can localise  in , log the error from the environment in which it occurred, then ensure the stack is cut back only to a point at which we can resume.

Here is a slightly more elaborate version taken from a commercial application. This application's user-interface object needs its error trapping to report what is in its  slot.