Index

Boolean aborted(name)

Return true if a catch enclosed statement has been aborted.

Example:
In the following example, a list of statements are run under the watchful eye of a catch statement. If any of these statements is aborted, then the $aborted() function call in the catch clause becomes momentarily true, making the catch clause true. This aborts the statements within the catch statement, then returns control, first to any remedial statement list of the catch statement, then to any statements that follow the catch statement.
 catch $aborted() | $signaled(source_set) {
   ...statements...
 } {
   print "Aborted"
 }
 print "Finished"

Context:
If a command in a scheduling script is aborted by a run-time error, or a schedule calls the abort command, then by default this aborts the whole schedule. However a schedule can choose to instead catch such an error and respond to it, by enclosing a set of statements that might be aborted, in a catch statement. The clause of this catch statement must call the aborted() function and evaluate to true when this function returns true.

The aborted() function returns true once per aborted command, and because catch clauses are tested from the innermost nested catch statement to the outermost catch statement, the innermost nested catch statement that calls the aborted() function, is the only one that will be triggered by the aborted command. For example, in the following,

  catch $aborted() {
    catch $aborted() {
      abort
    } {
      print "1"
    }
  } {
    print "2"
  }
  print "3"
only the innermost catch statement catches the effect of the abort command, such that this example would print 1 and 3, but not 2. However if this were modified to add another abort command in the remedial statements of the inner catch statement, as shown below, then the example would print 1, 2 then 3.
  catch $aborted() {
    catch $aborted() {
      abort
    } {
      print "1"
      abort
    }
  } {
    print "2"
  }
  print "3"
The aborted() function also catches the case of a user-defined command being aborted by the cancel command. Since the cancel command is usually invoked interactively by a user, rather than reflecting an error, this doesn't by default terminate the script. However if an enclosing catch statement that tests the aborted() function is found, then it is triggered by such an event.
Martin Shepherd (18-May-2010)