How can I abstract out a repeating try catch pattern in C++

前端 未结 7 1171
眼角桃花
眼角桃花 2020-12-15 04:28

I have a pattern that repeats for several member functions that looks like this:

int myClass::abstract_one(int sig1)
{
  try {
    return _original->abstr         


        
7条回答
  •  自闭症患者
    2020-12-15 05:11

    I don't have an answer except to suggest that you might be better off avoiding exception handling altogether and relying instead on Smart Pointers and Boost Scope Exit to do all your resource clean up. That way you won't have to catch exceptions unless you can do something about them, which is rarely the case. Then you can do all exception handling in one centralized place higher up the call chain for error reporting and such.

提交回复
热议问题