Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: the try/catch example from "Programming Perl" analyzed

by hardburn (Abbot)
on Aug 19, 2004 at 19:58 UTC ( #384430=note: print w/replies, xml ) Need Help??

in reply to Re^2: the try/catch example from "Programming Perl" analyzed
in thread the try/catch example from "Programming Perl" analyzed

I have yet to find a case in which I would want to throw an object.

I have. Specifically, I want to do different things for different errors, and extract information from it. For instance, Exception::Class provides full information about the uid/gid, package, file, line number, stacktrace, pid, and so on. Sure, it'd be possible to encode all that into a single string, but the extraction process isn't as easy. Further, you might want to provide some information to the user, and send more details to the developer. It's much easier (and safer) to do that with an object than trying to munge a string.

Besides Java code doing the same thing is usualy several times longer than its Perl conterpart so I don't think these three or four additional lines matter. That is unless you program Java in perl.

It's not just the extra lines, but the extra level of indentation. Like I said, Java programmers typically operate with 4-space indents, because they know they're going to take a lot more space for indentation than other langs (and also because the identifiers tend to be much longer). However, most Perl programmers can easily get away with 8-space indents. As such, every extra level of indentation is a big deal.

Other people have given solutions which get rid of that extra level. My prefered is to place the string into an exception object and then handle it like any other exception..

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

  • Comment on Re^3: the try/catch example from "Programming Perl" analyzed

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-01-19 21:04 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (56 votes). Check out past polls.