Perl error handling

When routines in the Rational® ClearQuest® API encounter unexpected conditions, they throw an exception. If the exception is not caught by the calling program, the language interpreter terminates your program. If there is any possibility that the Rational ClearQuest API call will fail, you should catch and handle exceptions.

Use the standard means of handling Perl errors by using the Perl eval statement to analyze errors. Use the following syntax:

eval {enter statements you want to monitor};

At runtime, if the Perl engine encounters an error in a statement in the eval block, it skips the rest of the eval block and sets $@ to the corresponding error text.

For example

eval{$objectName->MethodName();};
   if ($@)
      {
      print "Error using MethodName method. Error: $@\n";
      }
else
   {
      # continue without error ...
   }

Several functions which are expected to commonly fail are exceptions to this. In particular, validate and set field functions return error indications instead of throwing exceptions. For more information, see "Error checking and validation".


Feedback