Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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
Node Status?
node history
Node Type: note [id://384430]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-01-18 09:20 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (161 votes). Check out past polls.