Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does JVM handles RuntimeException(s)

While creating custom exceptions, If we want to create a checked Exception we extend the Exception class and for unchecked exception we extend the RuntimeException class. My question is, how JVM handles subClasses of RuntimeException and Exception differently when they all are sub classes of the Exception class.

like image 692
gaurs Avatar asked Jul 17 '14 08:07

gaurs


People also ask

Can runtime exception be caught in Java?

Catching Exception or Throwable Catching Exception will catch both checked and runtime exceptions. Runtime exceptions represent problems that are a direct result of a programming problem, and as such shouldn't be caught since it can't be reasonably expected to recover from them or handle them.

Do we need to handle runtime exceptions in Java?

Thus, the compiler does not require that you catch or specify runtime exceptions (although you can). One case where it is common practice to throw a RuntimeException is when the user calls a method incorrectly. For example, a method can check if one of its arguments is incorrectly null .


1 Answers

It doesn't. The only difference is in requirements enforced by the compiler.

like image 194
chrylis -cautiouslyoptimistic- Avatar answered Oct 05 '22 22:10

chrylis -cautiouslyoptimistic-