Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Error wrapping in an OO moduleby Fang (Pilgrim) |
on Jun 28, 2005 at 08:54 UTC ( [id://470531]=perlquestion: print w/replies, xml ) | Need Help?? |
Fang has asked for the wisdom of the Perl Monks concerning the following question: Hi all, I am writing an OO module for my own needs (and as a learning experience as well), and I am trying to gather all the error messages possibly emitted by other modules (DBI, mainly). So far, I have laid down the following course of action:
The private variable is simply called _error, accessed by an error() method that simply returns the string and resets _error to the empty string. So far, this works fine under the environment I am using (mod_perl), with one little issue: if the constructor method encounters an error and returns undef, I can't use it like this for obvious reason: my $obj = MyModule->new() or die $obj->error();DBI uses a global variable for a similar purpose I believe, any caveat I should be aware of before trying that myself? To sum it up, I am looking for advices concerning any better method I couldn't think of to achieve the same thing, whether it is a commonly used and proven solution, or an existing module (I have searched for "error", "wrapper", and many variations thereof but didn't quite find a fitting tool). Thanks in advance for any advice you will provide.
Back to
Seekers of Perl Wisdom
|
|