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 }
|
---|
In Section
Seekers of Perl Wisdom