简体   繁体   English

C ++,捕获错误作为引用时出现Segfault

[英]C++, Segfault when catching error as refernce

when I catch any exception as a reference and try to access it with e.what(), I get an Segfault. 当我捕获任何异常作为参考并尝试使用e.what()访问它时,我得到了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,我得到:

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) 我使用了:Ubuntu clang版本3.6.0-2ubuntu1〜trusty1(标签/ RELEASE_360 / final)(基于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 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可以为我解决问题。

解决方案:删除编译器标志-lc ++ abi对我来说解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM