wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compiler time error with respect to exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

Compiler time error with respect to exception handling

Sirish Kumar
Greenhorn

Joined: Jan 28, 2004
Posts: 15
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

Joined: Jan 28, 2004
Posts: 15
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiler time error with respect to exception handling