-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.4, 1.2.0
-
x86, sparc
-
solaris_2.6, windows_95
allan.jacobs@Eng 1997-10-20
The following example is motivated by Modena test n1419206.
// import java.io.IOException;
class X {
static void check_unexception () {
try{ }
catch( Exception e) { System.out.println(e); }
}
static void check_unreachable () {
try{ }
catch( Throwable e) { System.out.println(e); }
}
public static void main( String[] argv ) {
X.check_unthrowable();
X.check_unexception();
}
}
Section 14.19:
"A catch block C is reachable iff both of the following are true:
* Some expression or throw statement in the try block is reachable and
can throw an exception whose type is assignable to the parameter of the
catch clause C. (An expression is considered reachable iff the
innermost statement containing it is reachable.)
* There is no earlier catch block A in the try statement such that the
type of C's parameter is the same as or a subclass of the type of A's
parameter.
Are the println's reachable? Javac says so but the spec (at least by
the most direct reading) says not. Which catch block arguments do make
their catch block's unreachable when their corresponding try blocks are
empty?
=========================================================================
Here's another test case from ###@###.###. I would expect this one to fail at compile-time also.
brian.klock@eng 1998-07-23
//-----------------------------Test1.java---------------------------
public class Test1 {
public static void main(String args[]) throws Exception
{
try { throw new Exception(); }
catch(SubException e) { System.out.println("Caught 1"); }
try { m(); }
catch(SubException e) { System.out.println("Caught 2"); }
}
static void m() throws Exception { throw new SubException(); }
}
class SubException extends Exception { }
- duplicates
-
JDK-4046575 JLS3 14.21 Spec for reachability doesn't consider unchecked exceptions
- Closed