The largest Interview Solution Library on the web

« Previous | 1 | 2 | 3 | Next »

Jdk7 - More Precise Re throwing of Exception

The Java SE 7 compiler performs more precise analysis of re-thrown exceptions than earlier releases of Java SE. This enables you to specify more specific exception types in the throws clause of a method declaration.

before JDK 7, re-throwing an exception was treated as throwing the type of the catch parameter.
For example, if your try block can throw ParseException as well asIOException. In order to catch all exceptions and rethrow them,

You would have to catch Exception and declare your method as throwing an Exception. This is sort of obscure non-precise throw, because you are throwing a general Exception type (instead of specific ones) and statements calling your method need to catch this general Exception. This will be more clear by seeing following example of exception handling in code prior to Java 1.7.
« Previous | 1 | 2 | 3 | Next »

copyright © 2014 - all rights riserved by