aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is Throwble a checked Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is Throwble a checked Exception" Watch "Is Throwble a checked Exception" New topic
Author

Is Throwble a checked Exception

Simran Dass
Ranch Hand

Joined: Jan 09, 2010
Posts: 183


When we give :-

throw new Throwable();

If we do not either handle or declare the exception compilation fails.
So is Throwable a checked exception. What should be the answer to foll question :-


a) Throwable is a checked exception ? ( True or False)

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What is the definition of an unchecked exception ? If you know it, you'll know what type of exception Throwable is. Check the answer in the Java Specification.


[My Blog]
All roads lead to JavaRanch
Simran Dass
Ranch Hand

Joined: Jan 09, 2010
Posts: 183

The specification says : -


The unchecked exceptions classes are the class RuntimeException and its subclasses, and the class Error and its subclasses. All other exception classes are checked exception classes.


So, this means Throwable is a checked exception
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Simran Dass wrote: So, this means Throwable is a checked exception

Yes that's right. You could've also created a simple program which throws an object of type Throwable and not catch it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
The Throwable class is the superclass of all errors and exceptions in the Java language


So it can be both checked and unchecked.


SCJP 1.6 96%
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820


So it can be both checked and unchecked.

Hold on a second...
It isn't both checked and unchecked


The unchecked exceptions classes are the class RuntimeException and its subclasses, and the class Error and its subclasses. All other exception classes are checked exception classes.


is Throwable a RuntimeException or one of its subclasses? No
is Throwable an Error or one of Error's subclasses ? No

if you do as Ankit suggested and try to throw an unchecked throwable, it won't compile
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
Throwable is super class of RuntimeException and Error so it contains them too, thats why when you throw a throwable you can catch it or not as per your wish.
If you dont catch a throwable compiler will not complain which is the case with RuntimeExceptions and Errors.

Throwable is superclass of all Exceptions, so it contains both checked and unchecked exceptions.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Neha Daga wrote:when you throw a throwable you can catch it or not as per your wish.
If you dont catch a throwable compiler will not complain

Did you try it out??
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Yow can't throw a Throwable without catching it. You can't say that it is both checked and unchecked exceptions
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
sorry, I didn't try it and gave a wrong answer.
And i was a bit confused in my thoughts and I guess I wrote the other way round.

you guys are correct.
Simran Dass
Ranch Hand

Joined: Jan 09, 2010
Posts: 183

Thanks

I had already tried it with code before posting the question but was
confused (same confusion as Neha's). My question contains -

throw new Throwable();

If we do not either handle or declare the exception compilation fails.



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is Throwble a checked Exception