Reputation: 1499
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.
Upvotes: 0
Views: 17714
Reputation: 792
The above answered are very much informative. I just want to add:
The Master Base Class:
java.lang.Object
The Master Exception Class:
java.lang.Throwable
The Master Exception Class extends Throwable
:
java.lang.Exception
and java.lang.Error
The Unchecked class extends Exception
extends Throwable
:
java.lang.RuntimeException
Upvotes: 0
Reputation: 16698
Below image will help you to understand Exception
Hierarchy
Image Ref: programcreek:
As you can see Throwable
is super class of Error and Exception while Exception
deals with checked and unchecked Exception.
The term exception is shorthand for the phrase "exceptional event."
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.
Upvotes: 11
Reputation: 1325
From the javadocs:
java.lang.Object
|
->java.lang.Throwable
|
->java.lang.Exception
Hope this clears the doubt.
Upvotes: 1
Reputation: 73578
The javadocs are for this. Here you can see that Throwable is the superclass for all Exceptions
and Errors
. Then you have checked and unchecked Exceptions
, where the latter is RuntimeException
and all its subclasses.
Remember to use Google when you're wondering about things like this, because all this information is widely available and easily found with a search engine.
Upvotes: 3