When I run this in linux machine, I expect the catch block to catch the exception. Whereas I get a segmentation fault. Why is this ? Should it not print "Caught exception"
void handle_eptr(std::exception_ptr eptr) // passing by value is ok
{
try {
if (eptr) {
std::rethrow_exception(eptr);
}
} catch(const std::exception& e) {
std::cout << "Caught exception \"" << e.what() << "\"\n";
}
}
int main()
{
char *c =(char*) 0x10;
std::exception_ptr eptr;
try {
std::string s = c;
} catch(...) {
std::cout<< "Caught exception";
//eptr = std::current_exception(); // capture
}
// handle_eptr(eptr);
std::cout << "Normal Exit";
}