Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
    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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Compiler time error with respect to exception handling

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,
This is with respect to the exception handling rules. I understand
that any method that can throw a checked exception must take one of the
following approaches
1.Declare the checked excpetion in the throws clause OR
2.Provide the try/catch clause
Now consider the following method
//Approach 1
public void raise() throws IOException
{
//empty method
}

//Approach 2
public void raise()
{
try
{
//empty block
}
catch(IOException a)
{
}
}

While there is no problem with snippet 1, in case of snippet 2 the compiler
reports that the java.io.IOException is not thrown in the body of the
method. I could not understand the difference in this behaviour..
Further if the IOException is replaced with Exception then both the snippets are fine. Again this was not what I was expecting since Exception and all its subclasses (other than the RuntimeException branch) are checked
exceptions.
Any comments regarding the above 2 problems???
Thanks
 
Sirish Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,
Sorry for posting the same question again. Sorry for the slip-up. I have got good replies to the same question posted earlier. Please do continue in the old thread and do not post replies to this one
Thanks a bunch
Compile Time error
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic