Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Do you use an exception class in your Perl programs? Why or why not?

by creamygoodness (Curate)
on Mar 15, 2010 at 00:03 UTC ( [id://828620]=note: print w/replies, xml ) Need Help??


in reply to Do you use an exception class in your Perl programs? Why or why not?

I sometimes use exception objects because catching exceptions based on class is less fragile than catching exceptions based on examining the error message.

if ($@) { # Fragile. if ($@ =~ /My error message/) { ... } else { die $@ } # Robust. if (blessed($@) and $@->isa("MyError")) { ... } else { die $@ } }
  • Comment on Re: Do you use an exception class in your Perl programs? Why or why not?
  • Download Code

Replies are listed 'Best First'.
Re^2: Do you use an exception class in your Perl programs? Why or why not?
by TGI (Parson) on Mar 15, 2010 at 04:59 UTC

    Parsing strings is fragile and error prone.

    Imagine if we had to pass our subroutine arguments and return values as strings.

    Without exception objects, that it the situation with exceptions. It really bothers me that I have to parse a string to identify an exception type. Especially since the raw data that produced the string should be available.

    This is the fundamental reason I've been obsessing about exceptions lately.


    TGI says moo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2025-11-12 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.