• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Doubt Reg. Exceptions

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}
}
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What? What, what, what? What what tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic