Voorbeeld

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( "Probleem", 10 ); //$NON-NLS-1$
}

public static void main(String[] args){
try {
createProblem();
}catch (Exception e){
if ( e instanceof SomeException ) {
System.out.println( ((SomeException)e).getValue() );
} else {
System.out.println( e.getLocalizedMessage() );
e.printStackTrace();
}
}
}

Oplossing
Verwijder instanceof-controles uit uitzonderingen en voeg vast toegewezen afvangclausules toe aan het try/catch-blok.

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( "Probleem", 10 ); //$NON-NLS-1$
}

public static void main(String[] args){
try {
createProblem();
} catch ( SomeException e ){
System.out.println( ((SomeException)e).getValue() );
}
}