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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error wrapping in an OO module
by tlm (Prior) on Jun 28, 2005 at 09:59 UTC | |
by Fang (Pilgrim) on Jun 28, 2005 at 10:13 UTC | |
|
Re: Error wrapping in an OO module
by mattk (Pilgrim) on Jun 28, 2005 at 23:37 UTC |