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

Exception Doubt

 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

THis is related to the same question asked by Amit Taneja(dan exam doubt 15 ). Well i changed the code a little bit and got a doubt. Here it goes:

The program is:


The code above doesnt give any compiler error. My doubt is that a++ is not reachable, shouldnt the compiler throw an error?

The same code i right this way


This code doesnt compile, it says "a++" as unreachable block.

So what i guess is that, in the first code the compiler may not know whether the m1 method throws the exception or not. But in the second code the compiler very well knows that the exception is thrown and so a++ is not reachable.

Am i right?

Thanks
 
Adam Czysciak
Ranch Hand
Posts: 90
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

The program is:


The code above doesnt give any compiler error. My doubt is that a++ is not reachable, shouldnt the compiler throw an error?

[...cut...]

Am i right?


No - the throws statement doesn't say it *will* throw the exception, but only that method *might* throw an exception. Therefore compiler doesn't know whether 'a++' statement will be reachable or not. Wel, the smart one could predict it, but I'm not sure what JLS says about whether it can or not do so.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic