In the main method above, the last clause catches the generic java.lang.Exception. Instead,
create a dedicated catch clause for each declared exception that is thrown from the try clause.
Note: There may be situations when a generic catch is preferred to ensure graceful exits. In general
however, greater clarity and options for greater control are possible with more specific catch clauses.
public static class Loader {
public void load() throws UnsupportedOperationException, ClassNotFoundException {
}
}
public static void main(String[] args) {
Loader loader = new Loader();
try {
loader.load();
} catch ( UnsupportedOperationException e1 ) {
System.out.println( "load is not implemented" );
} catch ( ClassNotFoundException e2 ) {
System.out.println( "No class " + e2.getMessage() );
}
}
|
|