Kavin Velusamy
Kavin Velusamy

Reputation: 17

Why I can't be able to catch Exceptions under Object class reference when Object class is the super class for all?

From my research on google, most sites say that "Throwable" is the ultimate superclass for Exceptions. I accept it, but even when Throwable is a sub-class of Object class why I can't able to store exceptions under Object class?

https://i.sstatic.net/3EZsz.jpg

Upvotes: 0

Views: 44

Answers (1)

user13784117
user13784117

Reputation: 1132

You can't throw an arbitrary object because the language says you can't: JLS 14.18

You can't catch an arbitrary object because the language says you can't: JLS 14.20

The intent is to restrict exception objects to a particular hierarchy.

Upvotes: 3

Related Questions