Hi,
Wondering if anyone could help me understand this but it seems that I can't get exceptions in C++ to work properly.
I'm using: Linux box 4.1.13-piCore_v7+ #1 SMP PREEMPT Thu Dec 3 14:16:36 CET 2015 armv7l GNU/Linux
When I compile the following code, using g++ (5.3.0):
#include <exception>
#include <iostream>
int main(int argc, char **argv)
{
try {
std::cout << "throwing" << std::endl;
throw std::exception();
} catch (std::exception& e) {
std::cout << "catching" << std::endl;
}
return 0;
}
I'll get:
throwing
terminate called after throwing an instance of 'std::exception'
Aborted
Running in gdb will give me:
(gdb) run
Starting program: /mnt/sda1/persistent/build/throw/a.out
throwing
terminate called after throwing an instance of 'std::exception'
Program received signal SIGABRT, Aborted.
0x76cf0950 in raise () from /lib/libc.so.6
(gdb) bt
#0 0x76cf0950 in raise () from /lib/libc.so.6
#1 0x76cf1cc8 in abort () from /lib/libc.so.6
#2 0x76f18644 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#3 0x76f16870 in ?? () from /usr/lib/libstdc++.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)
Running the same code on Ubuntu 14.04 will give me:
throwing
catching
as expected.
I tried adding the -fexceptions flag and also tried cross-compiling it on Ubuntu 14.04, using gcc (4.8.4) but with the same result.
What I'm I missing here?
Thanks,
Indridi