今天我在一个catch
块中发现了一个错误:
catch (const exception& e){
// do something
// throw e; <-- bug!
throw; // <-- right thing to do
}
基本上,如果我e
明确地重新抛出异常,我会得到一个新的std::exception
重建,实际上来自该what()
方法的消息是默认的std::string
,而不是我自定义的消息。
解释是什么?我以为这throw;
只是throw ExceptionJustCaught;
.