home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


B.7 Exception Handling

  1. die throws an exception, and eval traps it. Error string is found in $@ . The following code has the possibility of two run-time errors:

    eval {                         
       $c = $a / $b;                                       #1
       die "Denominator cannot be negative" if ($b < 0);   #2
    };
    print "Run-time error: $@";

    $@ can be "Illegal division by zero" at (1) or "Denominator cannot be negative" at (2).


Previous: B.6 Dynamic Behavior Advanced Perl Programming Next: B.8 Meta-Information
B.6 Dynamic Behavior Book Index B.8 Meta-Information

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.