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.