aspose file tools*
The moose likes Beginning Java and the fly likes The throw question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The throw question" Watch "The throw question" New topic
Author

The throw question

Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276


When I compile this, i get,

Adding 'throws MyException' to main() would solve this, but why am I getting this error in the finally block,while a very similar throw inside catch block works fine.
I just want JVM's default handler to catch the exception I throw from finally. Same with catch is very fine. Default handler gets it.

Is there something i'm doing wrong? Is there any helping explanation?

OCPJP 6
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

"Very similar" does not mean "the same".

An NPE is a RuntimeException. MyException is not. Checked exceptions *must* be either caught, or declared to be thrown. Runtime exceptions require neither.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
That looks very similar to what is discussed in this thread.
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

Thanks David & Campbell...I completely get that Checked/UnChecked Exceptions
I just have one more question in store, regarding this.
I tried extending 'RuntimeException' class instead of 'Exception' so that my custom exception could be an unchecked one, but i'm getting compile errors like

I just have extended RuntimeException which IS-A Throwable instance,right? though not directly. Can we not make our custom exceptions UnChecked?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

We'd have to see the current code in order to help.
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

oops..my mistake,my mistake. works fine when i subclass RuntimeException.
I just used 'RunTimeException' instead of 'RuntimeException'. I got some 7 compile errors..didn just focus on the very first one - cannot find symbol.
really am sorry to bother you people.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The throw question