when I catch any exception as a reference and try to access it with e.what(), I get an Segfault. Does anyone have an idea, why this happens?
#include <stdexcept>
#include <iostream>
int main(){
try{
throw ::std::runtime_error("test");
}catch(::std::exception const &e){
::std::cerr << e.what() << "\n";
}
}
I get:
bash: line 1: 22110 Segmentation fault (core dumped) 'test' < /dev/null > 'test.stdout' 2> 'test.stderr'
With ASAN I get:
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
I use: Ubuntu clang version 3.6.0-2ubuntu1~trusty1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)
on: Ubuntu 14.04.3 LTS,Linux ubuntu 3.13.0-76-generic #120-Ubuntu SMP Mon Jan 18 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Solution: Deleting -lc++abi solved the problem for me.
解决方案:删除编译器标志-lc ++ abi对我来说解决了这个问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.