Mail::Sender (the newest version) allows you to specify what kind of error reporting do you want. It can either throw an exception (die), return an undef or return a negative error number. This of course affects all methods of the created object as well. Therefore the caller can use whatever feels best for him:
You can do something similar.eval { my $sender = Mail::Sender->new({on_errors => 'die', ...}); $sender->Open({...}); ... $sender->Close(); }; die "Failed to send the email: $@\n" if $@; #or my $sender = Mail::Sender->new({on_errors => 'undef', ...}) or die "Failed to send the email: failed creating the object - $Mail +::Sender::Error\n" $sender->Open({...}) or die "Failed to send the email: $Mail::Sender::Error\n" ... $sender->Close() or die "Failed to send the email: $Mail::Sender::Error\n"; #or ...
Anyway ... I would not want some object to print whetever error messages it pleases into the STDOUT. I would not want them in the STDERR either, but even that would be better.
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
In reply to Re: Should a constructor ever return undef?
by Jenda
in thread Should a constructor ever return undef?
by tall_man
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |