aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Doubt 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 "Exception Doubt" Watch "Exception Doubt" New topic
Author

Exception Doubt

Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
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

Joined: Feb 25, 2005
Posts: 90
    
    5
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.


Adam
SCJA, SCJP 5.0, SCWCD 1.4, SCBCD 5, SCEA 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Doubt