On Fri, 2002-02-08 at 09:12, Steven Comrie wrote:
> Sorry for the off topic question, but I still think this list is one
> of the better places to ask fairly detailed O-O questions.
>
> I'm working on a new File Uploading module, and there are several
> cases when an error might be returned to the user, ie, 'File Selected
> for Upload does not exists', 'File type (extension) not allowed',
> 'File size too large', 'Disk quota exceeded', 'Unspecified error
> during upload' or 'File already exists (not in force over-write
> mode)'.
>
> I want a way to be able to return these error messages to whoever is
> using the module in a way that they can test for error message
> existence easily. I also want to keep the object interface nice and
> clean. Any suggestions on a good way to return error messages to the
> programmer so they can do with them what they see fit?
Whenever I run into a design issue like this, I look at some of the more
popular modules on CPAN and see how the they do it. Personally I like the
way DBI handles error messages. If you make a method call and don't get
anything back, you can query the DBI object for the last error number or
error message. So using DBI as an example, you can do something like this
(straight out of the docs):
my $sth = $dbh->prepare(q{
INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
}) || die $dbh->errstr;
So if your method call fails, you set the value of the last error in your
object and you return undef.
Cees
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]