Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should RuntimeException be extended?

This is more of an OO design question.

So, I've got an UnsuportedLocaleException which will be used only on the initialization stage of an app. I've got two options:

  1. Extend RuntimeException and leave it out there without any handling logics (acts as a config => apply defaults if wrong).
  2. Extend an Exception and handle it (involves all the redundant coding etc.).

I like the first one more, but not sure if that'll be correct design.

like image 700
Denys S. Avatar asked Apr 25 '26 17:04

Denys S.


1 Answers

Seems entirely reasonable to me. RuntimeException is a good base class for exceptions which calling code shouldn't try to "handle" - i.e. when they indicate the kind of failure which probably means that either the whole app or (possibly, for servers) the request should simply be abandoned.

like image 59
Jon Skeet Avatar answered Apr 27 '26 07:04

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!