As a rule, I try not to throw Exception instances because this does not convey much information about what went wrong.
But I found that I am getting quite a few empty Exception classes that look like this:
class DataNotFoundException extends Exception {
Thus, the functionally class is identical to Exception. The only functional value - now I can do it ...
try { ... some code which throws exceptions ... } catch (DataNotFoundException $dnfe) { ... do stuff ... } catch (OtherException $oe) { ... do other stuff ... }
My question is, where is the balance between having a huge number of tiny Exception classes and just throwing Exception instances. Does anyone have any recommendations as to when to introduce a new Exception class?
source share