×
Home About Us Products Services News Free Scripts Contact
news php scripts and software

Perl example - How to catch exceptions with eval in Perl?


Perl - How to catch exceptions with eval in Perl?

This approach is useful when you wish to see the reason why the script "has died" in some part of the program.
 
Consider the following example:
 
  eval 
  {
     
     die("REASON"); # the script dies for some reason
 
  }; 
 
  if ($@) # $@ contains the exception that was thrown
  {
      print $@;
  }

Category: Perl

 
<< Go back