Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

darobin (1316)

darobin
  (email not shown publicly)
http://berjon.com/

Journal of darobin (1316)

Wednesday January 09, 2002
02:51 PM

Class based exceptions

[ #2016 ]

I'm building a rather large system (at least a system that can be built upon) and I've been wondering about how to allow those that build upon it to reuse its exception system.

My first thought was to simply use class based exceptions (as is done in Exception::Class, or in XML::SAX::Exception) but I've hit what I consider to be a fairly bothering problem.

That approach implies fudging with @ISA all over the place. This means that if two independent people choose the same name for their exception classes, one will overwrite the other. That's ok if they are both direct subclasses of the base exception class.

But in the other cases, if those two exception classes have different @ISAs, then one of them won't behave the way that was intended, but will still throw exceptions and not complain. Code that checks isa() might however not work as expected.

So I've been pondering a BaseException->register('Class') scheme that would take care of that properly (by checking that an exception class hasn't yet been registered) but it seems clunky (though it may be the best approach). Does anyone have other solutions they'd like to share ? It's not that I want to force people to pay attention, but I don't want the framework I'm building to make it too easy to create hard-to-track-down bugs.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.