-1

When a null pointer exception occurs it immediately kills the program, without the need to add throw declarations to all methods.

I am looking for this kind of behaviour for some of my own exceptions. They are critical. If they can occur my program as a whole becomes useless, even if I would catch them. Hence I don't want to catch them, but want to see them immediately. I also don't want to spoil the code by adding throw declarations up to the root of the method tree.

How is this done in Java? In other languages there is the exit() command, but with the disadvantage of not getting the full stack trace of exceptions.

Blcknx
  • 1,921
  • 1
  • 12
  • 38

1 Answers1

-1

You have to use unchecked or RuntineExceptions.

Exceptions that are extending the Exception-Class are checked exceptions that have to be catched or thrown by the Method.

Unchecked Exceptions are Exceptions that extend RuntimeException like IllegalArgumentException or NullPointerException.

You can create own unchecked Exceptions. That way you can decide inside your code when to throw an unchecked exception and don't have to catch it or put it at the end of your Method-Signature.

Michael Seiler
  • 650
  • 1
  • 5
  • 15