I have an inherited class C1 that implements interface I, which may raise some exceptions.
I want to create a class C2 that also implements interface I, which is based on an instance of C1, but catches all the exceptions and does something useful about them.
Currently my implementation is as follows:
class C2 implements I { C1 base; @Override void func1() { try { base.func1(); } catch (Exception e) { doSomething(e); } } @Override void func2() { try { base.func2(); } catch (Exception e) { doSomething(e); } } ... }
(Note: I could also make C2 a continuation of C1. It does not matter for the current question).
The interface contains many functions, so I have to write the same try ... catch block again and again.
Is there a way to reduce the amount of code duplication here?
source share