Index

catch condition {commands} {remedial_commands}

Abort the specified block of commands if a given condition becomes true.

Arguments:
Boolean condition
The condition who's truth value aborts the block of commands.
commands
A block of commands to execute. The commands will be executed to completion unless the condition becomes true.
remedial_commands
An optional block of commands to execute if the condition becomes true.

Example:
In the following example, if the source sets while the enclosed statements are being executed, or the statements take more than 10 minutes to complete, execution of these statements is aborted, and execution resumes with the print statement that follows the catch statement.
  catch $signaled(source_set) | $elapsed > 10m {
    track jupiter
    until $acquired(source)
    until $elapsed > 30s
    track blank
    until $acquired(source)
    until $elapsed > 10m
  }
  print "Finished"
Example:
This example is similar to the previous one, except that here an extra block of remedial commands has been provided. This block of commands is only executed if the catch condition becomes true. In this case it tells the user that the statements had to be aborted, and why. After it has finished executing, execution continues with the print statement that follows the catch statement.
  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"
Context:
Catch commands provide a way to abort a block of commands when specified events occur. This is important when using until statements, because these can block script execution indefinitely, and unless every one of these until commands checks all conceivable conditions, it is possible that script execution will be held up much longer than intended. For example, in the following example, if Jupiter or Saturn were to set before the telescope reached them, the script would pause until they rose again.
  track jupiter
  until $acquired(source)
  until $elapsed > 30s
  track saturn
  until $acquired(source)
  until $elapsed > 30s
One 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.

Martin Shepherd (1-Dec-1999)