Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^7: Perl try { } catch(e) { }

by Haarg (Curate)
on Jun 18, 2021 at 04:10 UTC ( #11133983=note: print w/replies, xml ) Need Help??


in reply to Re^6: Perl try { } catch(e) { }
in thread Perl try { } catch(e) { }

PPI is in no way robust enough for this use case. Source filters will never be appropriate for production use.
use strict; use warnings; use experimental 'signatures'; use Nice::Try; sub foo { 1 } try { my $k = sub ($f = foo()) {}; } catch ($e) { warn "caught: $e"; } __END__ Global symbol "$e" requires explicit package name (did you forget to d +eclare "my $e"?) at bad-syntax.pl line 10. syntax error at bad-syntax.pl line 10, near ") {" Execution of bad-syntax.pl aborted due to compilation errors.
The module has other serious issues:
use strict; use warnings; use Nice::Try; { package MyException; use overload '""' => 'message'; sub message { $_[0]->{message} } sub new { my $class = shift; bless { @_ }, $class } sub throw { my $class = shift; die $class->new(message => shift) } } try { MyException->throw("hi\n"); } catch (MyException $e) { warn "working catch: $e"; } catch ($e) { warn "broken catch: $e"; } __END__ $ perl bad-exception.pl broken catch: hi at bad-exception.pl line 21.

Replies are listed 'Best First'.
Re^8: Perl try { } catch(e) { }
by jdeguest (Sexton) on Jun 18, 2021 at 11:31 UTC
    Thank you for taking the time and test it, much appreciate it.
    use experimental 'signatures';
    Yes, this (sub ($f = foo())) messes it up. I will add a disclaimer. Hopefully there won't be much frequency of that happening.
    The module has other serious issues:
    Yes, this mishandling of overloaded exception was a bug that I just resolved in version 1.1.2 now available on CPAN. Thank you again for helping me make it better!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-10-26 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?