catch condition {commands} {remedial_commands}
Abort the specified block of commands if a given condition becomes true.
Boolean
condition
commands
remedial_commands
catch $signaled(source_set) | $elapsed > 0:10:0 { track jupiter until $acquired(source) until $elapsed > 0:0:30 track saturn until $acquired(source) until $elapsed > 0:10:0 } print "Finished"
catch $signaled(source_set) | $elapsed > 0:10:0 { track jupiter until $acquired(source) until $elapsed > 0:0:30 track saturn until $acquired(source) until $elapsed > 0:10:0 } { if($signaled(source_set)) { print "The source set" } else { print "Observations took too long" } exit } print "Finished"
track jupiter until $acquired(source) until $elapsed > 0:0:30 track saturn until $acquired(source) until $elapsed > 0:0:30One could deal with this by adding a "
|
$signaled(source_set)
" clause to each of the until
statements, but this becomes troublesome if there are a lot of
such statements, and could be impossible if the code is being
imported from somebody else's file.
Both of these problems are resolved by enclosing the
block of statements in a catch block, and writing the stopping
condition just once.
catch $signaled(source_set) { until $acquired(source) until $elapsed > 0:30:0 track saturn until $acquired(source) until $elapsed > 0:30:0 }Note that the catch condition is only evaluated at certain times. It is evaluated just before the first of its enclosed statements is about to be run, whenever a script
signal
arrives, and
repeatedly while until statements are running.
If the condition is found to be true at any of these points, then the
enclosed block of statements is aborted. Specifically, what happens is
as follows:
at_end
command to register
termination cleanup statements, then those statements are
executed, starting from those of the innermost nested
command.
The clauses of nested catch statements are scanned in order from the
innermost catch statement to the outermost catch statement. After each
scan through these clauses, the outermost catch statement whose clause
is found to be true, is the one that aborts its enclosed
statements. So if two or more nested catch statements test the same
condition, and that condition doesn't change while the clauses are
being scanned, then it is the outermost of these catch statements that
aborts the statements that it encloses. However if the triggering
event is an aborted command, then it is the innermost of these catch
statements that aborts its commands, because
the aborted()
function that tests for this event, only
returns true
for the first catch statement clause that
invokes it, after an abort.