Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Error codes vs die exceptions vs ...

by LanX (Sage)
on Jul 06, 2019 at 16:02 UTC ( #11102480=note: print w/replies, xml ) Need Help??


in reply to Re: Error codes vs die exceptions vs ...
in thread Error codes vs die exceptions vs ...

Thanks!

... what I like about your approach is that you can distinguish between different exception classes ( literally so)

> Exception handling allows error handling in localised and easily recognised places

Well I seem to remember that exception handling needs to propagate too, if the class can't be handled locally.

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

  • Comment on Re^2: Error codes vs die exceptions vs ...

Replies are listed 'Best First'.
Re^3: Error codes vs die exceptions vs ...
by GrandFather (Saint) on Jul 07, 2019 at 12:25 UTC

    Exceptions propagate until they are handled which may be at the outermost level by Perl handling the die. Nothing between the code throwing the exception and the node handling it sees the exception.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
      Sorry, I should have been clearer

      > > if the class can't be handled locally.

      let's say you want to catch one exception class directly but delay handling of other classes to higher scopes ...

      Then you'd need to propagate the unhandled exception classes again in the first catch{...} to reach the next catch{...}

      ... right?

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

        Then you'd need to propagate the unhandled exception classes

        That's true for Try::Tiny. My first encounter with Perl's exceptions "beyond eval/die" was Error, which is much like Java in that it allows you to catch a particular error class, and passes all other errors on. TryCatch also does this, but I've never used it.

        Error has its quirks as is clearly indicated in the module's description (section "Warnings"), and TryCatch uses the spooky Devel::Declare, so getting accustomed to propagate unhandled errors is probably a good idea.

        In Perl, yes. It's different for most strongly typed languages though I believe. There an exception bubbles up the stack of error handlers until it reaches one that feels responsible for it. Or none, but then it crashes the program.


        holli

        You can lead your users to water, but alas, you cannot drown them.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2022-01-21 09:27 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?