C++,捕获错误作为引用时的隔离错误
C++, Segfault when catching error as refernce
当我捕获任何异常作为引用并尝试使用 e.what() 访问它时,我得到一个 Segfault。有没有人知道,为什么会这样?
#include <stdexcept>
#include <iostream>
int main(){
try{
throw ::std::runtime_error("test");
}catch(::std::exception const &e){
::std::cerr << e.what() << "n";
}
}
我得到:
bash: line 1: 22110 Segmentation fault (core dumped) 'test' < /dev/null > 'test.stdout' 2> 'test.stderr'
使用ASAN,我得到:
ASAN:SIGSEGV
=================================================================
==21318==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x2af35c5534bf bp 0x7ffc1b30ee30 sp 0x7ffc1b30ee10 T0)
#0 0x2af35c5534be (/media/psf/Home/test+0xf54be)
#1 0x2af35ebf4ec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
#2 0x2af35c4a68a6 (/media/psf/Home/test+0x488a6)
AddressSanitizer can not provide additional info.
==21318==ABORTING
我使用: Ubuntu clang 版本 3.6.0-2ubuntu1~trusty1 (tags/RELEASE_360/final) (基于 LLVM 3.6.0)
上: Ubuntu14.04.3 LTS,Linux ubuntu 3.13.0-76-generic #120-Ubuntu SMP 周一 1月 18 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
解决方案:删除 -lc++abi 为我解决了问题。
解决方案:删除编译器标志 -lc++abi 为我解决了这个问题。
相关文章:
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- C++引用错误
- 已定义函数时出现 G++ "未定义的引用"错误
- 错误:使用通用引用的声明冲突
- 链接 cmake 时出现未定义的引用错误
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 链接器错误:未定义对"Reference_Genome::seq[abi:cxx11]"的引用
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 错误:无法解析对重载函数的引用;你的意思是调用它吗?
- 在 gtest 中初始化堆栈上的引用变量的隔离错误
- 运行时错误:引用绑定到类型为"int"的空指针
- 隐式重新解释引用时强制转换,没有警告/错误
- 只有级联分类器会发出未定义的引用错误
- 错误:未定义对cv::cudacodec::createVideoReader的引用
- 模板流运算符重载错误:引用初始化无效,与basic_istream和basic_ifstream之间的差异有关
- 对于我的 ComplexNumber 中的某些方法,我得到了一个奇怪的未定义错误引用.cpp,不过我对模板很陌生
- 从对象调用成员对象,错误:引用非常量值的初始值必须是左值
- Qt并发错误:引用非静态成员