Java Reference
In-Depth Information
Because you can now specify static void monitor() throws Pres-
sureException, TemperatureException , you can provide more precise
handlers where monitor() is called, as the following example demonstrates:
try
{
monitor();
}
catch (PressureException pe)
{
System.out.println("correcting pressure problem");
}
catch (TemperatureException te)
{
System.out.println("correcting temperature problem");
}
Because of the improved type checking offered by final rethrow, source code that
compiled under previous versions of Java might fail to compile under Java 7. For ex-
ample, consider Listing 3-28 .
Listing 3-28. Demonstrating code breakage as a result of final rethrow
class SuperException extends Exception
{
}
class SubException1 extends SuperException
{
}
class SubException2 extends SuperException
{
}
class BreakageDemo
{
public static void main(String[] args) throws SuperEx-
ception
{
try
{
Search WWH ::




Custom Search