2 ms·
This design claims MyBrandSpankingNewException was: * So different we just couldn't represent it as MyExistingException and yet * So similar that it's fine to
by tialaramex 4y ago
This design claims MyBrandSpankingNewException was:
* So different we just couldn't represent it as MyExistingException and yet
* So similar that it's fine to just treat it as MyBaseException everywhere
In my experience everywhere I see this pattern all we're doing with MyBaseException is giving it to a human, via logging, stderr, or whatever, which means this is a lot of complexity to just move some text.
Although this strategy didn't formally "break client code" in practice if it matters the code will need to be rewritten to actually handle MyBrandSpankingNewException.
- d0mine 4y agoUsually a derived exception is a special case of the base exception e.g., OSError -> FileNotFoundError. Sometimes you want to handle specific error differently and sometimes you don't care. btw, it may be the reason to create a new subclass, to distinguish between cases when you do care.