Fed*_*dor 41 c++ exception language-lawyer
以下程序抛出nullptr异常,然后捕获异常int*:
#include <iostream>
int main() {
try {
throw nullptr;
}
catch(int*) {
std::cout << "caught int*";
}
catch(...) {
std::cout << "caught other";
}
}
Run Code Online (Sandbox Code Playgroud)
在 Clang 和 GCC 中,程序成功打印caught int*, demo: https://gcc.godbolt.org/z/789639qbb
但是在 Visual Studio 16.11.2 中,程序打印caught other. 这是 MSVC 中的错误吗?
ale*_*ame 39
根据标准[except.handle],看起来像是 Visual Studio 中的错误:
\n\n\n\n
E处理程序与类型为if的异常对象匹配[...]
\n\n
\n- 处理程序的类型为
\ncv Torconst T&其中T是 apointer或pointer-to->member类型并且E是std\xe2\x80\x8b::\xe2\x80\x8bnullptr_t。
| 归档时间: |
|
| 查看次数: |
1425 次 |
| 最近记录: |