try
{
// code that could cause exception
}
catch (const std::exception &exc)
{
// catch anything thrown within try block that derives from std::exception
std::cerr << exc.what();
}
#include <exception>
try
{
// The code that could throw
}
catch(...)
{
auto expPtr = std::current_exception();
try
{
if(expPtr) std::rethrow_exception(expPtr);
}
catch(const std::exception& e) //it would not work if you pass by value
{
std::cout << e.what();
}
}