javaexceptionthrowable

What is the built in base class to handle all exceptions in Java


What is the built in base class to handle all exceptions in Java? Is It Exception or Throwable?

What is the difference between two builtin classes,can someone explain me.


Solution

  • Below image will help you to understand Exception Hierarchy

    enter image description here

    Image Ref: programcreek:

    As you can see Throwable is super class of Error and Exception while Exception deals with checked and unchecked Exception.

    Exception

    The term exception is shorthand for the phrase "exceptional event."

    Throwable:

    The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the argument type in a catch clause. For the purposes of compile-time checking of exceptions, Throwable and any subclass of Throwable that is not also a subclass of either RuntimeException or Error are regarded as checked exceptions.