aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

Roll
Ranch Hand

Joined: Jan 20, 2000
Posts: 52

Getting a compilation error as
ex6.java:31: Exception java.io.IOException is never thrown in the body of the corresponding try statement.
catch(IOException e) {
^
1 error.

Why So!!!

[This message has been edited by Paul Wheaton (edited January 29, 2000).]
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20271
    ∞

I hope you don't mind, I went and put CODE statements around your source so it would be easier to read.
(for more info, go to http://www.javaranch.com/ubb/ubbcode.html)


Shore nuff. The try block doesn't throw any exceptions, except maybe a divide by zero exception.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Roll
Ranch Hand

Joined: Jan 20, 2000
Posts: 52
But when the exception was not caught finally should be printed.But its not printing finally in this code.
WHY???
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20271
    ∞

Ohhhhh! Now I see your question.
At frist I was going to say that maybe it throws an Error instead of an exception, but I checked and that isn't it. So I put the code into the copiler and the compiler barfed.
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Test.main(Test.java:9)
That's why it doen't do finally. You can't run the program unless you can compile it. You can't compile it because you don't have any code that throws an IOException in your try block.
I changed the IOException to Exception and it ran fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions
 
Similar Threads
checked exception
Exception Never Thrown error
Finally
catch block.....
Class Exception