DaemonLost class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 5: Line 5:
The <var>[[Run (Daemon function)|Run]]</var> function of the <var>[[Daemon_class|Daemon]]</var> system class is an example of a system method that automatically throws a <var>DaemonLost</var> exception. For more information about catching a thrown exception, see "[[Try and Catch]]".
The <var>[[Run (Daemon function)|Run]]</var> function of the <var>[[Daemon_class|Daemon]]</var> system class is an example of a system method that automatically throws a <var>DaemonLost</var> exception. For more information about catching a thrown exception, see "[[Try and Catch]]".
   
   
The following example shows a "[[Try and Catch]]" of a <var>DaemonLost</var> exception. The daemon request is contrived to produce a user restart to demonstrate <var>DaemonLost</var> exception output.  
The following example shows a <var>Try</var> and <var>Catch</var> of a <var>DaemonLost</var> exception. The daemon request is contrived to produce a user restart to demonstrate <var>DaemonLost</var> exception output.  
<p class="code">begin
<p class="code">begin
   %dmn    is object daemon
   %dmn    is object daemon
Line 38: Line 38:
<p class="code">begin
<p class="code">begin
   %dmn  is object daemon
   %dmn  is object daemon
   %prog  is object [[Stringlist class|stringlist]]
   %prog  is object stringlist
   
   
   %dmn = new
   %dmn = new
   %prog = new
   %prog = new
   [[Text_and_Html_statements#The_HTML_or_TEXT_statement|text to]] %prog
   text to %prog
       begin
       begin
         assert 1 eq 2
         assert 1 eq 2
Line 48: Line 48:
   end text
   end text
   
   
   [[try]] %dmn:run(%prog)
   try %dmn:run(%prog)
       if %dmn:lastCommandErrorCount then
       if %dmn:lastCommandErrorCount then
         print 'Error in daemon!'
         print 'Error in daemon!'
       end if
       end if
   [[catch]] daemonLost
   catch daemonLost
       [[PrintText statement|printText]] Caught a DaemonLost.
       printText Caught a DaemonLost.
   end try
   end try
end
end
Line 60: Line 60:
To produce a <var>DaemonLost</var> exception for a user-created method, you would issue a <var class="product">User Language</var> <var>[[Throw]]</var> statement from within the method, and you must catch it in the code that called the method.  Because this exception is tailored to <var>daemon</var> execution by the system <var>Run</var> method, you are not likely to throw it from a user method, unless you want the method to <var>[[Catch]]</var> and then <var>Throw</var> the exception to the code that called the method.  For example, your method might contain code like this:
To produce a <var>DaemonLost</var> exception for a user-created method, you would issue a <var class="product">User Language</var> <var>[[Throw]]</var> statement from within the method, and you must catch it in the code that called the method.  Because this exception is tailored to <var>daemon</var> execution by the system <var>Run</var> method, you are not likely to throw it from a user method, unless you want the method to <var>[[Catch]]</var> and then <var>Throw</var> the exception to the code that called the method.  For example, your method might contain code like this:
<p class="code">%dLost is object daemonLost
<p class="code">%dLost is object daemonLost
   [[try]] %dmn:run(%whatever)
   try %dmn:run(%whatever)
   [[catch]] daemonLost to %dlost
   catch daemonLost to %dlost
       throw %dlost
       throw %dlost
   end try
   end try
Line 68: Line 68:
And the code that calls the method might contain:
And the code that calls the method might contain:
<p class="code">%daemLost is object daemonLost
<p class="code">%daemLost is object daemonLost
[[try]] %obj:mymethod
try %obj:mymethod
[[catch]] daemonLost to %daemLost
catch daemonLost to %daemLost
   printText Daemon lost!
   printText Daemon lost!
   %daemLost:daemonOutput:print
   %daemLost:daemonOutput:print

Revision as of 14:50, 10 May 2011


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 more information about catching a thrown exception, see "Try and Catch".

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.

begin %dmn is object daemon %sl is object stringlist %daemonLost is object daemonLost %dmn = new %sl = new text to %sl begin print 'Rosebud' end begin 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 Daemon class Run method.

A request cancellation does not cause the daemon thread to go away, so it does not produce a DaemonLost exception. Consequently, using the error count on the last command may be an adequate way for your application to check for a request cancellation:

begin %dmn is object daemon %prog is object stringlist %dmn = new %prog = new text to %prog begin 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 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 DaemonLost methods

The following are the available DaemonLost class methods.

MethodDescription
DaemonOutputStringlist copy of last output stream of lost daemon thread
NewCreate a new DaemonLost object

The methods in the class are described in the subsections that follow. In addition:


DaemonOutput property

Stringlist copy of last output stream of lost daemon thread (DaemonLost class)

This ReadOnly property returns a Stringlist that contains a copy of the output of the last stream the daemon thread was running before it was lost (probably restarted). The contents of this stringlist might be useful in determining why the daemon thread was restarted.

Syntax

%sl = daemonLost:DaemonOutput

Syntax terms

%sl This Stringlist contains a copy of the daemon thread's last output. The Stringlist may be empty, that is, have no items.
%daemonLost A reference to an instance of a DaemonLost object.

New constructor

Create a new DaemonLost object (DaemonLost class) This constructor generates an instance of a DaemonLost exception. As shown below, the optional argument of the New method is a setting of the DaemonOutput property.

Syntax

%daemonLost = [%(DaemonLost):]New[( [DaemonOutput= stringlist])]

Syntax terms

%daemonLost A reference to an instance of a DaemonLost object.
%(DaemonLost) The class name in parentheses denotes a shared method.
DaemonOutput This optional, but name required, parameter specifies the Stringlist (stringlist) to be assigned to the DaemonLost exception object's DaemonOutput property when a daemon thread is lost.