Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Error codes vs die exceptions vs ...

by choroba (Archbishop)
on Jul 05, 2019 at 21:36 UTC ( #11102462=note: print w/replies, xml ) Need Help??


in reply to Error codes vs die exceptions vs ...

If the failure happens in a subroutine that's deeply nested in many other subroutines, but you need to catch the error somewhere near the top (e.g. to retry the whole operation), it's hard to propagate the error correctly. Throwing an exception (preferably an exception object for easy logging) solves the problem. It doesn't clutter the code, but it should still be used with caution, as the flow is much harder to follow - throwing an exception is just a goto in disguise!

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Error codes vs die exceptions vs ...
by LanX (Sage) on Jul 06, 2019 at 13:49 UTC
    > but it should still be used with caution, as the flow is much harder to follow - throwing an exception is just a goto in disguise!

    IMHO from inside deeply nested routines you can only to create a report, which is a $SIG{__DIE__/__WARN__} in disguise.

    Anything else is maintenance hell.

    Exceptions - which are not necessarily errors - should be handled as close as possible/reasonable otherwise you get "global" programming where you need to handle non local events.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-01-21 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?