...
Improved Exception Handling
Java 7 introduced an improved checking for rethrown exceptions. Previously, a rethrown exception was treated as throwing the type of the catch parameter. Now, when a catch parameter is declared final, the type is known to be only the exception types that were thrown in the try block and are a subtype of the catch parameter type.
This new feature introduced two source incompatibility with respect to Java 6. The code below illustrates the changes. Previously, the statement throw exception would throw a Foo exception. Now, it throws a DaughterOfFoo exception. As a consequence, the catch block catch(SonOfFoo anotherException) is not reachable anymore as the try only throws a DaughterOfFoo exception.
Code Block |
---|
class Foo extends Exception {}
class SonOfFoo extends Foo {}
class DaughterOfFoo extends Foo {}
class Test {
void test() {
try {
throw new DaughterOfFoo();
} catch (Foo exception) {
try {
throw exception; // first incompatibility
} catch (SonOfFoo anotherException) {
// second incompatibility: is this block reachable?
}
}
}
}
|
Java 7 introduced an improved checking for rethrown exceptions. Previously, a rethrown exception was treated as throwing the type of the catch parameter. Now, when a catch parameter is declared final, the type is known to be only the exception types that were thrown in the try block and are a subtype of the catch parameter type.
This new feature introduced two source incompatibility with respect to Java 6. The code below illustrates the changes. Previously, the statement throw exception would throw a Foo exception. Now, it throws a DaughterOfFoo exception. As a consequence, the catch block catch(SonOfFoo anotherException) is not reachable anymore as the try only throws a DaughterOfFoo exception.
Use Case 6:
Evaluation
| Final Array & Anonymous Class | Generic Constructors | Capture Conversion Idiom | Overloaded Methods | Covariant Arrays | Improved Exception Handling |
---|---|---|---|---|---|---|
JTL |
| X | X |
| X |
|
BBQ | X | X | X | ? | X |
|
SOUL |
|
|
|
|
|
|
JQuery | X | X | X | ? | X |
|
.QL |
|
|
|
| X |
|
Jackpot |
|
|
|
|
|
|
PMD |
|
|
|
| X |
|
...