This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt Reg. Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt Reg. Exceptions" Watch "Doubt Reg. Exceptions" New topic
Author

Doubt Reg. Exceptions

Ravi Pinnaboyina
Greenhorn

Joined: Feb 19, 2007
Posts: 11
Why is this saying Unreachable code...?? Anything special for IOException

public static void main(String args[])
{

try
{
}
catch(java.io.IOException t)
{
System.out.println("Inside Catch");
}
}
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Are you sure unreachable code is the error or is it that IOException is not thrown in the try block?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

There is nothing inside the try block that could possibly throw an IOException. Therefore, the catch block is unreachable.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Ravi Pinnaboyina
Greenhorn

Joined: Feb 19, 2007
Posts: 11
Is it that U need a code that can generate IOException to have a catch block for IOException.

Is this same even for remaining Exceptions ???

Then If dont write a any code and keep an Exception catch block why is this not complaining?
Is this behaviour specific to IOException only???
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18508
    
  40

Originally posted by Ravi Pinnaboyina:
Is it that U need a code that can generate IOException to have a catch block for IOException.

Is this same even for remaining Exceptions ???

Then If dont write a any code and keep an Exception catch block why is this not complaining?
Is this behaviour specific to IOException only???


An Exception includes checked exceptions like the IOException, and unchecked exceptions, as RuntimeException is a subclass of the Exception. This behavior is specific to all checked exceptions.

Unchecked exceptions, and exceptions that include unchecked exceptions, can't be confirmed to not be thrown, hence, allowed.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Consider Paul's rocket mass heater.
 
subject: Doubt Reg. Exceptions
 
Similar Threads
WA #1.....word association
JavaRanch Olympics
JSP init parameters.
about object serialization
5 letter scrabble