Should I extend a RuntimeException?

It is rather a matter of OO design.

So, I have a UnsuportedLocaleException that will be used only at the application initialization stage. I have two options:

  • Extend RuntimeException and leave it there without processing logic (acts as config => apply default values ​​if they are wrong).
  • Extend the exception and handle it (includes all redundant coding, etc.).

I like the first one, but I'm not sure if it will be the right design.

+3
source share
3 answers

. RuntimeException , "", , , , , , (, ), .

+9

- . , RuntimeException.

+2

.

() , . , . , , . . , try/catch if.

. , , . , . , Spring .

So the answer is what you are developing. If it is a standalone library, use checked, well-defined exceptions. If this is an application or application framework, you can use runtime exceptions like Spring.

+2
source

Source: https://habr.com/ru/post/1791542/


All Articles