Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • The problem of needing to localise special variables is discussed in http://perldoc.perl.org/perlobj.html#Destructors [perl.org].

    There is a P::C policy ErrorHandling::RequireCheckingReturnValueOfEval [cpan.org] that catches this programming mistake. Its documentation also offers an alternative approach where you don't need to mess with other people's destructors to make it work.

    package SomeClass;
    sub new {
        return bless \my $foo => __PACKAGE__;
    }

    sub DESTROY {
        eval {'resetting $@'};
    }

    package main;
    use strict;
    use warnings;

    if (
        eval {
            my $obj = SomeClass->new();
            die "Code Red!\n";
            1;
        }
    ) {
        print "Exception caught: $@\n";
    } else {
        print "No exception occurred\n";
    }

    • Did you mean to say

      if (
          eval {
              my $obj = SomeClass->new();
              die "Code Red!\n";
              1;
          }
      ) {
          print "No exception occurred\n";
      } else {
          print "Exception caught: $@\n";
      }