Our library extends another (third-party) library. When we create a child class in our library, and want to throw exceptions, should those exceptions extend the exceptions from the parent class or from our own namespace? For example:
class Their_Exception extends Exception {}
class Their_Class {}
class Their_Class_Exception extends Their_Exception {}
class Our_Exception extends Exception {}
class Our_Class extends Their_Class {}
class Our_Class_Exception extends Our_Exception {} // or Their_Class_Exception?
Is it better to keep our code as above, and extend our own namespace? The way I see it, we have these alternatives:
- Extend our own namespace, catching all possible
Their_Class_Exception
cases and throwingOur_Class_Exceptions
in their place (complete encapsulation, but in general could be a fair amount of rework) - Extend our own namespace, but only don't catch
Their_Class_Exception
inOur_Class
(probably means multiple catch blocks) - Extend
Their_Class_Exception
(seems counter-intuitive, could introduce bugs by catching the wrong exceptions)
Which of these is the best approach in general, in order to keep our code consistent?