aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception Error" Watch "Exception Error" New topic
Author

Exception Error

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
void priya() {
System.out.println("Start");
try{
System.out.println("Hello world ");
throw new FileNotFoundException();

}catch(EOFException e){//---------------------error
System.out.println("End of file");
}catch(FileNotFoundException ae){
System.out.println("File not found");
} finally{
System.out.println("Finally");
}
}

I got the error EOFException is never thrown in corresponding try statement.But the book says it will display
Start
Hello World
File not found
Finally.
Michael Valentino
Ranch Hand

Joined: Nov 01, 2005
Posts: 96
Is this a question? What book are you referring to? Is this the complete code sample? If it is, then you're correct. The EOFException will be seen by the compiler as unreachable code, and won't compile.
[ June 07, 2006: Message edited by: Michael Valentino ]

SCJP 1.4, SCWCD J2EE 1.4, SCJD J2SE 1.5, SCBCD J2EE 1.3, SCDJWS (In Progress)
Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
System.out.println("Start");
try{
System.out.println("Hello world ");
throw new FileNotFoundException();

}catch(EOFException e){//---------------------error
System.out.println("End of file");
}catch(FileNotFoundException ae){
System.out.println("File not found");
} finally{
System.out.println("Finally");
}
}

And given EOFException and FileNotFoundException are subclasses of IOException and further assuming this block of code is placed into a class.This is the question given.

I am referring K&B book.
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
EOFException is a checked exception.
To catch any of the checked exceptions, there must atlest be one statement
in the try block that may cause the same or its subclass exception.

so if you have

there will be a compiler error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Error