Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by haukex (Bishop)
on Jun 17, 2021 at 08:57 UTC ( #11133949=note: print w/replies, xml ) Need Help??


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

Anyway, try it, and you will see it is quite stable, but if you have any suggestion for improvement, I would very much welcome it.

Yes, sorry, I wasn't doubting the quality of the implementation of Nice::Try. Though PPI is certainly excellent, like all static Perl parsers it can't actually parse all of Perl. Sadly, all source filters suffer from the fact that they can be broken by things outside of their control, namely, the source code that they are inserted into.

With Perl 5.34:

use warnings; use strict; use experimental 'try'; print foo(); # prints "Caught an error: Argh..." sub foo { try { die( "Argh...\n" ); } catch( $wow ) { return( "Caught an error: $wow" ); } }

Replies are listed 'Best First'.
Re^8: Perl try { } catch(e) { }
by jdeguest (Sexton) on Jun 18, 2021 at 11:53 UTC
    Yes, sorry, I wasn't doubting the quality of the implementation of Nice::Try.

    I did work hard to develop it thinking it would benefit many, but there is always room for improvement, and I enjoy constructive criticism and perl monks is always a great place to get excellent feedbacks, so thank you.

    Though PPI is certainly excellent, like all static Perl parsers it can't actually parse all of Perl. Sadly, all source filters suffer from the fact that they can be broken by things outside of their control, namely, the source code that they are inserted into.

    Yes, it's true that although PPI is really good, it has its limitations. There will definitely be edge cases when PPI will fail, unfortunately. Right now, as of perl v5.34, there is an experimental implementation of try-catch and hopefully in the future, they will fully implement it. However, because it is a feature, the use experimental 'try'; must be added in each block where one wants to use try-catch.

    In the snippet you provided, Nice::Try would render the same result by the way.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2021-09-23 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?