Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error in try/catch/finally

 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried running the program, but it is giving some compilation error..
Can any one explain me why?? and what is wrong with the code?
Sonir
 
bill williams
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to catch the exception from the second tc.m1(). because it is not a runtimeexception
 
Seany Iris
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why cann't it compile. Who can explain it to me?Give the error:
TestClass.java:14: 'finally' without 'try'
finally { tc.m2(); }
^
1 error
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened if you take off this ; in that line : catch (MyException d) { };
Hope that it helps and that it works!!!
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Seany Iris:

Why cann't it compile. Who can explain it to me?Give the error:
TestClass.java:14: 'finally' without 'try'
finally { tc.m2(); }
^
1 error

It doesn't compile because of the; after your catch, so that the compiler wonders where your finally comes from!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic