an exception when wrapped inside an block. After the , the special variable contains the value passed from . Perl 5.005 added the ability to throw objects as well as strings. This allows better introspection and handling of types of exceptions. eval { open(FILE, $file) || die MyException::File->new($!); while (<FILE>) { process_line($_); } close(FILE) || die MyException::File->new($!); }; if ($@) { # The exception object is in $@ if ($@->isa('MyException::File')) { # Handle file exception } else { # Generic exception handling # or re-throw with 'die $@' } } The pseudo-signal can be trapped to handle calls to . This is not suitable for exception handling since it is global. However it can be used to convert string-based exceptions from third-party packages into objects. local $SIG{} = sub { my $err = shift; if ($err->isa('MyException')) { die $err; # re-throw } else { # Otherwise construct a MyException with $err as a string die MyException::Default->new($err); } }; The forms shown above can sometimes fail if the global variable is changed between when the exception is thrown and when it is checked in the statement. This can happen in multi-threaded environments, or even in single-threaded environments when other code (typically called in the destruction of some object) resets the global variable before the checking code. The following example shows a way to avoid this problem (see or ; cf. ). But at the cost of not being able to use return values: eval { # Code that could throw an exception (using 'die') but does NOT use the return statement; 1; } or do { # Handle exception here. The exception string is in $@ }; Several modules in the Comprehensive Perl Archive Network (CPAN) expand on the basic mechanism: provides a set of exception classes and allows use of the try/throw/catch/finally syntax. , and all allow the use of try/catch/finally syntax instead of boilerplate to handle exceptions correctly. is a base class and class-maker for derived exception classes. It provides a full structured stack trace in and . overloads previously defined functions that return true/false e.g., , , , , etc. This allows built-in functions and others to be used as if they threw exceptions. PHP // Exception handling is only available in PHP versions 5 and greater. try { // Code that might throw an exception throw new Exception('Invalid URL.'); } catch (FirstExceptionClass $exception) { // Code that