Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions

 
Roll
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 21741
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roll
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when the exception was not caught finally should be printed.But its not printing finally in this code.
WHY???
 
paul wheaton
Trailboss
Pie
Posts: 21741
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic