aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes No Unreachable error ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "No Unreachable error ?" Watch "No Unreachable error ?" New topic
Author

No Unreachable error ?

Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
In the following code, statement 'System.out.println("i="+i);' will never be reached. This could be identified during compilation by compiler and it should give 'Unreachable error"
Why this is not happening?



"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The javac compiler does not evaluate expressions looking for exceptions. For example, even if the expression were simply 5/0, the compiler will not assume that an exception will occur.

In addition, the Java compiler only looks at method headers, not method imlementations or javadoc. So javac will not know that Math.random() is always less than 1 and (int)Math.random() is always zero.
[ December 06, 2004: Message edited by: Mike Gershman ]

Mike Gershman
SCJP 1.4, SCWCD in process
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Thank you Mike.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: No Unreachable error ?
 
Similar Threads
Doubt in exception handling????
Exception Handling
ghost - unreachable statement
Exception Handling
unreachable Code inside try/catch and still code compiles, why?