The first, obvious solution is to use methods:
catch(IOException e1) {
doSomethingGeneral();
// do something only with this exception
doSomethingGeneralAgain();
}
That leaves some duplication though. At the price of verbosity, since Java doesn't have lambdas yet (but will in Java 8), you can extract the specific behavior inside some anonymous class:
catch(IOException e1) {
handleException(new Runnable() {
@Override
public void run() {
// do something only with this exception
}
});
}
where handleException() would work like this:
private void handleException(Runnable specificBehavior) {
// do something general
specificBehavior.run();
// do something general again
}
I can't wait for Java 8, which will allow rewriting this as:
catch(IOException e1) {
handleException(() -> {
// do something specific
});
}