DaemonLost class
The DaemonLost exception class indicates that a daemon thread associated with a daemon object was lost, most probably because of a user restart.
The Run function of the Daemon system class is an example of a system method that automatically throws a DaemonLost exception. For information about catching a thrown exception, see ?? refid=tryctch..
The following example shows a Try and Catch of a DaemonLost exception. The daemon request is contrived to produce a user restart to demonstrate DaemonLost exception output:
b %dmn is object daemon %sl is object stringList %daemonLost is object daemonLost %dmn = new %sl = new text to %sl b Print 'Rosebud' end b end text try %dmn:run(%sl) catch daemonLost to %daemonLost printText Daemon died! Its last words were: %daemonLost:daemonOutput:print end try end
The result of the preceding request shows the daemon output that was stored in the exception:
Daemon died! Its last words were: ROSEBUD
Note: It is necessary to declare the exception object in the main thread of the program, but instantiating it is taken care of by the Run method.
A request cancellation does not cause the daemon thread to go away, so it does not produce a DaemonLost exception. However, using the error count on the last command may be an adequate way for your application to check for a request cancellation:
b %dmn is object daemon %prog is object stringlist %dmn = new %prog = new text to %prog b assert 1 eq 2 end end text try %dmn:run(%prog) if %dmn:lastCommandErrorCount then Print 'Error in daemon!' end if catch daemonLost printText Caught a DaemonLost. end try end
To produce a DaemonLost exception for a user-created method, you would issue a User Language Language Throw statement from within the method, and you must catch it in the code that called the method. Because this exception is tailored to daemon execution by the system Run method, you are not likely to throw it from a user method, unless you want the method to Catch and then Throw the exception to the code that called the method.
For example, your method might contain code like this:
%dLost is object daemonLost try %dmn:run(%whatever) catch daemonLost to %dlost throw %dlost end try
And the code that calls the method might contain:
%daemLost is object daemonLost Try %obj:mymethod catch daemonLost to %daemLost printText Daemon lost! %daemLost:daemonOutput:print End Try
The methods in this class are listed at "List of DaemonLost methods".