Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Goto-labels for exception handling?

by LanX (Saint)
on May 10, 2018 at 01:00 UTC ( [id://1214305]=note: print w/replies, xml ) Need Help??


in reply to Re: Goto-labels for exception handling?
in thread Goto-labels for exception handling?

> Using goto to get out of a subroutine is not something I've seen before

that's supported in Perl, the call stacks are properly cleaned. *

> a variable behind the scene, 

The closure variable?

For the rest I'm not sure what you are trying to tell me. (Probably not to use exceptions at all for errors? )

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

*) from goto : it can be used to go almost anywhere else within the dynamic scope, including out of subroutines ( but it's usually better to use some other construct such as last or die.)

Replies are listed 'Best First'.
Re^3: Goto-labels for exception handling?
by RonW (Parson) on May 14, 2018 at 19:14 UTC
    For the rest I'm not sure what you are trying to tell me. (Probably not to use exceptions at all for errors? )

    I was presuming you want to avoid using die/eval for exception handling.

    Anyway, it is an interesting approach. But it is basically a shorthand for $errmsg = "message", goto ERRLABEL

    Shorthand is fine. In this case, however, I think it hides something that the coder using your approach needs to be very aware of: That it is goto. The biggest problem with that being the dynamic scope. If the coder forgets this, the coder will discover the code's control flow jumping to unexpected places.

      > The biggest problem with that being the dynamic scope. If the coder forgets this, the coder will discover the code's control flow jumping to unexpected places.

      Exactly and thank you for getting to the point.

      Contrary to die I can react to the case of a missing "receptor".

      But what if this supposedly missing labeled was already used somewhere up the dynamic scope?

      I think this could be solved... but I wanted to see if this wheel was already invented before.

      Unfortunately does already the mention of "goto" cause a lot of unrelated emotions ... :/

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

        Personally, when it helps readability and maintainability, I have used goto - just very very rarely. Usually, where goto might be used, last can be used, though sometimes requires also using an error variable.

        As for "missing receptors", the only idea I have come up with is to make sure that all "goto" labels are unique. A major problem doing this is finding all the labels. (Maybe Perl::Critic can help with this.) Pre- or post- fixing labels can reduce collisions, but this is very tedious extra work. Maybe defining Pluggable keywords, for example, throw and catch could automate this.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-28 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found