Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How do I report an error back to the user of my object?

by thargas (Deacon)
on Jun 05, 2012 at 12:23 UTC ( #974441=note: print w/ replies, xml ) Need Help??


in reply to How do I report an error back to the user of my object?

You want to report an error during initialization. Personally, I consider that an error in creating an object should die, returning either an exception object or an error message in $@, according to your preference. This means that you'd have something like (untested):

package CoolObject; sub new { my $class = shift; my $self = { name => 'new' }, $class; $self->loaddata() or die 'Error loading data'; return $self;

and call it like

my $co = CoolObject->new(); # or if you want to trap the error... my $co = eval { CoolObject->new() }; if ($@) { # do something about the error }


Comment on Re: How do I report an error back to the user of my object?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2015-07-28 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls