Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have exceptions that doesn't need to be caught in Java?

Tags:

java

I would like to throw a custom exception that will be determined at runtime. Currently I have to either add throws to the function or surround it with a try catch. What I want is for this exception to not be caught at all. It is a fatal exception and will show the programmer the error and what he can do to fix it. This is for an abstract class checking if initialization has been run first. I would like it to act like a NullPointerException, as when it occurs the program crashes.

Thanks

like image 993
Bobbake4 Avatar asked Aug 05 '11 18:08

Bobbake4


1 Answers

Subclass RuntimeException instead of Exception.

I obviously don't know the design decisions behind this, but it seems like there may be a better way to achieve whatever you're trying to do.

like image 178
Collin Avatar answered Oct 04 '22 06:10

Collin