• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception Error

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic