Exception slicing - is this due to generated copy constructor?

后端 未结 4 1652
抹茶落季
抹茶落季 2020-12-15 10:56

I\'ve just fixed a very subtle bug in our code, caused by slicing of an exception, and I now want to make sure I understand exactly what was happening.

Here\'s our b

4条回答
  •  眼角桃花
    2020-12-15 11:24

    A quick google suggests that yes, you're throwing the copy constructor is required and must be public. (Which makes sense, as you're initializing a copy of e and throwing that.)

    Anyway, just use throw without specifying the exception object, to rethrow what was caught in the catch. Shouldn't that solve the problem?

      catch(Exception& e)
      {
        printf("Exception seen here! %s %d\n", __FILE__, __LINE__);
        throw;
      }
    

提交回复
热议问题