Can't get try/catch block compiled successfully

From: lonelyplanet999 (lonelyplanet999_at_my-deja.com)
Date: 11/29/03


Date: 29 Nov 2003 12:16:28 -0800

Hi,

I'm studying 310-035 exam with "Java 2 - Sun Certified Programmer &
Developer for Java 2 (310-035)" by Kathy Sierra, Bert Bates as
reference book.

I met one question about exception that confuses me.

The question asked what would happened if below code segment (enclosed
by /====) were placed into a class. The correct answer was 'The code
will not compile because of System.out.print statement just before the
first catch block. It also said that if this statement were removed,
the code would compile and code output: Start Hello world File Not
Found.

However, as I removed this statement I found compilation failed with
below error:

Ch4q11a.java:16: exception java.io.EOFException is never thrown in
body of corresponding try statement
    catch (EOFException e) {
    ^
1 error

Actually, whether I placed throw new FileNotFoundException or throw
new EOFException or not placing any throw exception statement in the
try block makes no difference: the compiler either complained the
throw exception statment unreachable or the exception statement is
never thrown in the body of the corresponding try statement.

Can I trust the book's answer description ? If yes, what code still
missing ?
Tks 3:o)

import java.io.*;

class Ch4q11a {

  public static void main (String [] args) {
//============================
    System.out.print("Start ");
    try {
      System.out.print("Hello world");
      throw new FileNotFoundException();
    }
    System.out.print(" Catch Here ");
    catch (EOFException e) {
      System.out.print("End of file exception");
    }
    catch (FileNotFoundException e) {
      System.out.print("File not found");
    }
//============================
  }

}



Relevant Pages

  • Re: MI is sloppy
    ... at compile time, for objects whose behavior is then known ... First of all, this is a contract ... it has it's own dedicated exception. ... fix some technically incorrect programs (in manpower, performance, ...
    (comp.lang.ada)
  • Re: capture error - the better way?
    ... This is Perl. ... Yes, runtime and compile ... Recall that the example here was a runtime error causing an exception ...
    (perl.beginners)
  • Re: HLA Stdlib v2.2 is now available.
    ... HLA code. ... Do you really think I post this code when it doesn't compile? ... The exception handling semantics are completely wrong. ...
    (alt.lang.asm)
  • Re: capture error - the better way?
    ... that runtime exception must happen at runtime, ... it is the duty of an optimizer never to change ... compile time only to find a divide by zero exception should write code ... If the optimizer changes program behaviour then you ...
    (perl.beginners)
  • Re: CompileAssemblyFromDom problem
    ... Turns out this was related to the account not having sufficient permissions ... no compile time errors coming back. ... > problem would result in an exception - not fail silently. ... works fine on other 2003 server ...
    (microsoft.public.dotnet.general)