What is the recommended way to deal with exceptions from C++?

I don't really need to trap them, but I'd at least like to see them. I compiled 
the C++ lib with `-g` and I am using the **cpp** backend with `importcpp` 
wrappers. With ``lldb`, I see the line of C++ which throws the exception: 
    
    
    (lldb) bt
    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS 
(code=1, address=0x18)
        frame #0: 0x0000000100010437 
foo.exe`colonanonymous__wRTldVNfvmb9aFVVqjJYXRw() + 199
        frame #1: 0x00007fff6b4d3dfe libc++abi.dylib`std::__terminate(void 
(*)()) + 8
        frame #2: 0x00007fff6b4d3be2 
libc++abi.dylib`__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 27
        frame #3: 0x00007fff6b4c6bb9 libc++abi.dylib`__cxa_throw + 113
      * frame #4: 0x0000000100124b89 
libpbbam.0.22.0.dylib`PacBio::BAM::BamFile::BamFilePrivate::RawOpen(this=0x0000000100f02f60)
 const at BamFile.cpp:93
        frame #5: 0x0000000100123bf7 
libpbbam.0.22.0.dylib`PacBio::BAM::BamFile::BamFilePrivate::BamFilePrivate(this=0x0000000100f02f60,
 fn="") at BamFile.cpp:38
    ...
    (lldb) up
    frame #4: 0x0000000100124b89 
libpbbam.0.22.0.dylib`PacBio::BAM::BamFile::BamFilePrivate::RawOpen(this=0x0000000100f02f60)
 const at BamFile.cpp:93
       92               if (f->format.format != bam)
    -> 93                   throw std::runtime_error{"BamFile: expected BAM, 
encountered un supported format: " +
       94                                            filename_};
    (lldb) p filename_
    (std::__1::string) $0 = "foo"
    
    
    Run
    
    
    $ ./foo.exe
    bam:foo
    hi
    then:foo
    now:foo
    Traceback (most recent call last)
    foo.nim(55)              foo
    foo.nim(49)              main
    system.nim(4341)         :anonymous
    SIGSEGV: Illegal storage access. (Attempt to read from nil?)
    
    
    Run

See? It does not tell me the exception. In fact, there seems to be an error in 
the actual throwing of the exception, even though the string seems to be valid.

[https://github.com/bio-nim/pbbam/blob/f5a659e9fbed4b675f4458734fdfc9fe8162b2ac/nim/foo.nim](https://github.com/bio-nim/pbbam/blob/f5a659e9fbed4b675f4458734fdfc9fe8162b2ac/nim/foo.nim)

Reply via email to