Entfernen Sie Prüfungen auf Ausnahmebedingungen mit 'instanceof', und fügen Sie zum try/catch-Block dedizierte catch-Klauseln hinzu.
public static class SomeException extends Exception{
public SomeException(String str, int value ){
super( str );
this .value = value;
}
public int getValue() {
return value;
}
private int value;
}
public static void createProblem() throws SomeException {
throw new SomeException( "Problem", 10 );
}
public static void main(String[] args){
try {
createProblem();
} catch ( SomeException e ){
System.out.println( ((SomeException)e).getValue() );
}
}
|
|