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 > 10m { track jupiter until $acquired(source) until $elapsed > 30s track blank until $acquired(source) until $elapsed > 10m } print "Finished"
catch $signaled(source_set) | $elapsed > 10m { track jupiter until $acquired(source) until $elapsed > 30s track blank until $acquired(source) until $elapsed > 10m } { if($signaled(source_set)) { print "The source set" } else { print "Observations took too long" } exit } print "Finished"
track jupiter until $acquired(source) until $elapsed > 30s track saturn until $acquired(source) until $elapsed > 30sOne 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 > 30s track saturn until $acquired(source) until $elapsed > 30s }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 new signal arrives, and repeatedly while until statements are running. If the condition is found to be true at any of these points, the enclosed block of statements is aborted, and if the optional block of remedial commands has been provided, it is executed. Then execution continues with the first statement that follows the catch command.