When Do You Use Exception or Error in Java ?

Throwable class is the superclass of Exception and Error classes in Java.

When you want to catch the exceptional conditions that your program can create or encounter, then use the Exception class or subclass of Exception.

When you come across situations that are unexpected then use Error class in Java. Also recovering from Error is not possible in most of cases. So it is better to terminate the program



You May Interest

What is the Difference Between Fail-fast and Fail-safe Iterator i ...

What is the Difference Between an Iterator and ListIterator in Ja ...

What is the Advantage of Using Unicode Characters in Java ?

Why Should You Define a Default Constructor in Java ?

Can We Use Thread.sleep Method For Real-time Processing in Java ?