DaemonLost class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (tags and edits)
Line 1: Line 1:
<!-- DaemonLost class -->
<!-- DaemonLost class -->
The DaemonLost exception class indicates that a daemon thread associated
The <var>DaemonLost</var> exception class indicates that a daemon thread associated with a daemon object was lost, most probably because of a user restart.
with a daemon object was lost, most probably because of a user restart.
   
   
The [[Run (Daemon function)|Run]] function of the Daemon system class is an example
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.
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.
==Examples==
The daemon request is contrived to produce
<ol><li>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:
a user restart to demonstrate DaemonLost exception output:
<p class="code">begin
<p class="code"> b
  %dmn    is object daemon
%dmn    is object daemon
  %sl    is object stringList
%sl    is object stringList
  %daemonLost is object daemonLost
%daemonLost is object daemonLost
   
   
%dmn = new
  %dmn = new
%sl = new
  %sl = new
text to %sl
  [[Text_and_Html_statements#The_HTML_or_TEXT_statement|text to]] %sl
  b
      begin
    Print 'Rosebud'
        print 'Rosebud'
  end
      end
   b
      begin
end text
   end text
   
   
try %dmn:run(%sl)
  [[try]] %dmn:run(%sl)
  catch daemonLost to %daemonLost
  [[catch]] daemonLost to %daemonLost
  printText Daemon died! Its last words were:
      [[PrintText statement|printText]] Daemon died! Its last words were:
  %daemonLost:daemonOutput:print
      %daemonLost:daemonOutput:print
end try
  end try
end
end
</p>
</p>
   
   
The result of the preceding request shows the daemon output that was
The result of the preceding request shows the daemon output that was stored in the exception:
stored in the exception:
<p class="output">Daemon died! Its last words were:
<p class="code"> Daemon died! Its last words were:
ROSEBUD
ROSEBUD
</p>
</p>
'''Note:'''
<b><i>Note:</i></b> It is necessary to declare the exception object in the main thread of the program, but instantiating it is taken care of by the <var>[[Run (Daemon function)|Run]]</var> <var>[[Daemon_class|Daemon]]</var> method.
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
<li>A request cancellation does not cause the daemon thread to go away, so it does not produce a <var>DaemonLost</var> exception. Consequently, using the error count on the last command may be an adequate way
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:
for your application to check for a request cancellation:
<p class="code"> b
<p class="code">begin
  %dmn  is object daemon
  %prog  is object stringlist
   
   
%dmn   is object daemon
  %dmn = new
%prog is object stringlist
  %prog = new
  [[Text_and_Html_statements#The_HTML_or_TEXT_statement|text to]] %prog
      begin
        assert 1 eq 2
      end
  end text
   
   
%dmn = new
  [[try]] %dmn:run(%prog)
%prog = new
      if %dmn:lastCommandErrorCount then
text to %prog
        print 'Error in daemon!'
    b
      end if
    assert 1 eq 2
  [[catch]] daemonLost
    end
      [[PrintText statement|printText]] Caught a DaemonLost.
end text
  end try
end
try %dmn:run(%prog)
    if %dmn:lastCommandErrorCount then
      Print 'Error in daemon!'
    end if
catch daemonLost
    printText Caught a DaemonLost.
end try
end
</p>
</p>
 
To produce a DaemonLost exception for a user-created method, you would issue a User Language
<li>To produce a <var>DaemonLost</var> exception for a user-created method, you would issue a User Language Language <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>[[Catach]]</var> and then <var>Throw</var> the exception to the code that called the method.  For example, your method might contain code like this:
Language
<p class="code">%dLost is object daemonLost
Throw statement from within the method, and you must catch it in the code
  [[try]] %dmn:run(%whatever)
that called the method.
  [[catch]] daemonLost to %dlost
Because this exception is tailored to daemon execution by the system Run method,
      throw %dlost
you are not likely to throw it from a user method, unless you want the method to
  end try
Catch and then Throw 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
try %dmn:run(%whatever)
catch daemonLost to %dlost
    throw %dlost
end try
</p>
</p>
   
   
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
End Try
end try
</p>
</p>
</ol>
   
   
The methods in this class are listed at "[[List of DaemonLost methods]]".
==See Also==
<ul><li>For information about catching a thrown exception, see "[[Try and Catch]]".
<li>The methods in this class are listed at "[[List of DaemonLost methods]]".
</ul>
[[Category:System exception classes]]
[[Category:System exception classes]]

Revision as of 04:45, 22 April 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.

Examples

  1. 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 Run Daemon method.

  2. 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

  3. 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 Catach 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

See Also