DaemonLost class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Created page with "The '''DaemonLost exception class''' indicates that a daemon thread associated with a daemon object was lost, most probably because of a user restart. The [[Daemon methods#Run f...")
 
(Created page with "<!-- 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 [...")
Line 1: Line 1:
The '''DaemonLost exception class''' indicates that a daemon thread associated with a daemon object was lost, most probably because of a user restart.
<!-- DaemonLost class -->
 
The DaemonLost exception class indicates that a daemon thread associated
The [[Daemon methods#Run function|Run method]] 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 [[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:
with a daemon object was lost, most probably because of a user restart.
 
b
The [[Run (Daemon function)|Run]] function of the Daemon system class is an example
  %dmn is object daemon
of a system method that automatically throws a DaemonLost exception.
  %sl is object stringList
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:
<p class="code"> b
  %dmn   is object daemon
  %sl     is object stringList
  %daemonLost is object daemonLost
  %daemonLost is object daemonLost
  %dmn = new
  %dmn = new
  %sl = new
  %sl = new
  text to %sl
  text to %sl
  b
  b
  Print 'Rosebud'
    Print 'Rosebud'
  end
  end
  b
  b
  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 Daemon died! Its last words were:
%daemonLost:daemonOutput:print
  %daemonLost:daemonOutput:print
  end try
  end try
  end
  end
 
</p>
The result of the preceding request shows the daemon output that was stored in the exception:
 
The result of the preceding request shows the daemon output that was
Daemon died! Its last words were:
stored in the exception:
<p class="code"> Daemon died! Its last words were:
  ROSEBUD
  ROSEBUD
 
</p>
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.
'''Note:'''
 
It is necessary to declare the exception object in the main thread of
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:
the program, but instantiating it is taken care of by the Run method.
 
  b
A request cancellation does not cause the daemon thread to go away, so
  %dmn is object daemon
it does not produce a DaemonLost exception.
  %prog is object stringlist
However, using the error count on the last command may be an adequate way
for your application to check for a request cancellation:
<p class="code"> b
   
  %dmn   is object daemon
  %prog is object stringlist
  %dmn = new
  %dmn = new
  %prog = new
  %prog = new
  text to %prog
  text to %prog
  b
    b
  assert 1 eq 2
    assert 1 eq 2
  end
    end
  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 Caught a DaemonLost.
    printText Caught a DaemonLost.
  end try
  end try
  end
  end
 
</p>
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:
 
To produce a DaemonLost exception for a user-created method, you would issue a User Language
%dLost is object daemonLost
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:
<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
 
</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
%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>
The methods of the DaemonLost exception class are described in the following subsections.
 
The methods in this class are listed at "[[List of DaemonLost methods]]".
<h2 style="color: #990000">DaemonOutput property</h2>
[[Category:System exception classes]]
 
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.
 
%sl = %dLost:DaemonOutput
 
'''DaemonOutput syntax'''
 
; %sl
: This Stringlist contains a copy of the daemon thread's last output. The stringlist can be empty, that is, have no items.
; %dLost
: A reference to an instance of a DaemonLost object.
 
<h2 style="color: #990000">New constructor</h2>
 
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.
 
[%dLost =] [%(DaemonLost):] New[(DaemonOutput=outputList)]
 
'''New constructor syntax'''
 
; %dLost
: A reference to an instance of a DaemonLost object.
; DaemonOutput=outputList
: This name required parameter specifies the Stringlist (outputList) to be assigned to the DaemonLost exception object's DaemonOutput property when a daemon thread is lost.

Revision as of 20:15, 14 January 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 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".