• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt Reg. Exceptions

 
Ravi Pinnaboyina
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure unreachable code is the error or is it that IOException is not thrown in the try block?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing inside the try block that could possibly throw an IOException. Therefore, the catch block is unreachable.
 
Ravi Pinnaboyina
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21005
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic