I currently have some code I am trying to refactor. A large set of exceptions has some common code for all exceptions as well as some specific code which needs to be handled
In general, try
/catch
should only appear sparsely in the code. The problem is that many times the actions done in a catch
clause should also be done in case of early return, for example.
Idiomatic C++ uses RAII extensively to avoid situation where you need to cleanup in a catch
clause, which generally removes most of the work.
Now, your pattern is not so bad per se, it does factor the common stuff. But this common stuff could perhaps be handled automatically.
In all the code bases I have stumbled upon, only a few times did I see a genuine use of catch
clause, don't use it as a clutch.