| 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: 2341
|
|
|
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: 16695
|
|
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)
|
 |
 |
|
|
subject: Doubt Reg. Exceptions
|
|
|