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

"Aaaaahh I think I understood ..."

I don't (for the moment) - but i don't care about and just do:

#!/usr/bin/env perl use strict; use warnings; use Try::Tiny; try { die qq(Goodbye World!); } catch { warn $_; }; __END__

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^4: Perl try { } catch(e) { }
by jdeguest (Beadle) on Mar 24, 2021 at 03:29 UTC
    There is a full implementation of try-catch block using perl filters: Nice::Try So you can do something like embedded try-catch block, return, variable assignments, catching class exception, etc. There is no need for semicolon on the lack brace.
    use Nice::Try; try { # do something die( "Argh...\n" ); } catch( $wow ) { return( $self->error( "Caught an error: $wow" ) ); } finally { # do some cleanup }
    Full disclosure: I am the author of this module that I created when Devel::Declare on which TryCatch was relying became obsolete.
        they are very prone to making code extremely brittle
        Yes, it is true, but it largely depends on what the change are and how they are made. In the case of Nice::Try, the changes are carefully implemented and minimal and the module relies on PPI, which is way much safer than using regular expression. 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.
Re^4: Perl try { } catch(e) { }
by karlgoethebier (Abbot) on Mar 24, 2021 at 21:44 UTC

    See also

    «The Crux of the Biscuit is the Apostrophe»