Which is correct? catch (_com_error e) or catch (_com_error& e)?

后端 未结 4 2332
猫巷女王i
猫巷女王i 2021-02-19 11:36

Which one should I use?

catch (_com_error e)  

or

catch (_com_error& e)
4条回答
  •  执念已碎
    2021-02-19 12:05

    Definitely the second. If you had the following:

    class my_exception : public exception
    {
      int my_exception_data;
    };
    
    void foo()
    {
      throw my_exception;
    }
    
    void bar()
    {
      try
      {
        foo();
      }
      catch (exception e)
      {
        // e is "sliced off" - you lose the "my_exception-ness" of the exception object
      }
    }
    

提交回复
热议问题