Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

With a little tweaking of the code it can be done. I was playing around with it so there is more code in Splacker then needed.

#!/usr/bin/perl use warnings; use strict; BEGIN { # control eval's bypass of die $SIG{__DIE__} = \&Splacker; } my $error_log = ''; print $], "\n"; { package My::Obj; sub new { my $class = shift; bless {@_}, $class } sub DESTROY { my $self = shift; eval { 1 } if ! $self->{finished}; } } my $o1 = 'My::Obj'->new(finished => 1); undef $o1; # Exception Found. eval { my $o2 = 'My::Obj'->new; die "Exception 0!"; }; # And Caught if (Splacker()) { warn 'Caught with Splacker: '.Splacker(); } # Give back die control if you want... $SIG{__DIE__} = \&CORE::die; # Exception overlooked. eval { my $o2 = 'My::Obj'->new; die "Exception 1!"; }; if ($@) { warn "Caught with \$\@: $@"; } # Exception details lost. eval { my $o2 = 'My::Obj'->new; die "Exception 2!"; 1 } or do { warn "Caught with or: $@"; }; # Same as above. use Try::Tiny; try { my $o3 = 'My::Obj'->new; die "Exception 3!"; } catch { warn "Caught with Try::Tiny: $_"; }; sub Splacker { my $error = shift || ''; if ($error eq 'DIE') { print STDERR $error.' '.$error_log; CORE::exit(1); } elsif ($error) { $error_log = $error; # print STDERR $error; } else { return $error_log; } }
Output:
Caught with Splacker: Exception 0! at C:\xampp\cgi-bin\Test\tester.pl +line 33. Caught with or: at C:\xampp\cgi-bin\Test\tester.pl line 56. Caught with Try::Tiny: at C:\xampp\cgi-bin\Test\tester.pl line 67. 5.008008


In reply to Re^3: Bug in eval in pre-5.14 by $h4X4_|=73}{
in thread Bug in eval in pre-5.14 by choroba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-29 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found