0

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.

Akbar
  • 1,509
  • 1
  • 16
  • 32
  • Read the documentation of Error and compare it with that of Exception, both throwables but with different meanings. – Edwin Dalorzo May 08 '14 at 06:38
  • http://stackoverflow.com/questions/2129647/exception-vs-throwable-in-java check this out. This may solve your problem. – Aradhna May 08 '14 at 06:43

4 Answers4

11

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.

Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • where did you get this picture from? – chiccodoro May 08 '14 at 06:45
  • 2
    I know google but if you paste information here it is always a good idea to mention the source. First for credits and second for the reference of the readers. They may want to know the source of your claim so they can trust it and dig deeper into that resource if they are interested. Compare the other answers you say "from the javadocs..." – chiccodoro May 08 '14 at 06:50
  • @chiccodoro accepted sir. will follow from next time. thanks. – Vishrant May 08 '14 at 07:49
  • There is nothing stopping you from editing your answer and adding a URL. BTW I like your answer. I've just kept my upvote for the moment the reference slips in ;-) – chiccodoro May 08 '14 at 07:58
3

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.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
1

From the javadocs:

Class Exception

java.lang.Object
 |
 ->java.lang.Throwable
    |
    ->java.lang.Exception

Hope this clears the doubt.

Hungry Blue Dev
  • 1,313
  • 16
  • 30
0

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

Md. Jamal Uddin
  • 754
  • 8
  • 17