Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by zwon (Abbot)
on Mar 13, 2010 at 21:53 UTC ( [id://828486]=note: print w/replies, xml ) Need Help??


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

1. No I don't. I tried to use them, but failed to see how they can make my life easier, and code cleaner and more reliable, comparing to using die. When I'm using eval I usually just want to know if code succeed or failed, I can't remember right now any case where I wanted to perform different actions based on the $@ content. Some of my colleagues are actively using Exception::Class and, from my point of view, it doesn't make their code better. I just hate to see statements like:

do_something or MyCompany::Product::Subsystem::Module::Exceptions::IOE +rror->throw("Couldn't open $file: $!");

2. If I will learn how to use exception objects to improve my code quality I will immediately start to use them.

4. Yes, I think generally it is a bad idea. Redefining $SIG{__DIE__} may cause some hard to debug problems.

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 14, 2010 at 01:39 UTC

    I've been mostly underwhelmed with exception based techniques and exception objects. Try::Tiny has resolved many of my complaints with exceptions in general, so I am using them again.

    It bothers me to have to keep writing the likes of:

    if( $@ =~ /some error stuff/ ) { warn "error stuff occurred"; } else { warn "some other message" ; }

    An exception class system that works would remove the need for parsing data out of strings that should be available in a data structure.

    I feel like Perl exceptions are kind of like Perl OO in general. The language provides a bare minimum set of features that can be used to get things done, bat can also be extended in clever ways.

    We have 37 million Class::Foo modules that tried to build a better Perl object system. After years of experimentation, Moose hit the scene and has taken over.

    Is exception handling in Perl ripe for the introduction of a revolutionary module like Moose? What would it look like?

    Thanks for your thoughts.


    TGI says moo

      if( $@ =~ /some error stuff/ ) { warn "error stuff occurred"; } else { warn "some other message" ; }

      As I said I usually just do

      if($@) { Oops; }
      but now you mentioned it and I remember one case when I have to examine $@ content deeper. But usually I'm avoiding this, particularly because I don't see the way to do it clean.
      I feel like Perl exceptions are kind of like Perl OO in general.
      I feel that too. The problem is that $@ may contain any object, there's no standard interface to it. If there will be a module that change this situation, that would be great.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-18 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found