Today I found a bug in a catch block:

catch (const exception& e){
    // do something
    // throw e; <-- bug!
    throw;    // <-- right thing to do
}

Basically if I rethrow the exception e explicitly, I get a new std::exception reconstructed, in fact the message from the what() method was the default std::string, instead of my custom built message.

What is the explanation? I thought that throw; is only a shorthand of throw ExceptionJustCaught;.

Edit
Report