next up previous contents
Next: Using the eval() Function Up: Handling Errors and Signals Previous: Using the warn() Function

Trapping Fatal Errors

There are times when reporting fatal errors and then exiting the script are not appropriate responses to a problem.

For example, your script might try to use the alarm() function, which is not supported in some versions of Perl. Normally, using an unsupported function causes your problem to exit, but you can use the eval() function to trap the error and avoid ending the script.

The eval() function accepts an expression and then executes it. Any errors generated by the execution will be isolated and not affect the main program. However, all function definitions and variable modifications do affect the main program.