I have a library I use that throws something, but I don't know how to identify what was being thrown.
Sample code to reproduce this:
int main()
{
char* memoryOutOfBounds;
unsigned __int64 bigNumber = -1;
try {
throw std::string("Test");
memoryOutOfBounds = new char[bigNumber];
}
catch (const std::bad_alloc& ex)
{
printf("Exception: %s\n", ex.what());
}
catch (...)
{
printf("Unknown.\n");
}
return 0;
}
The new char[bigNumber]
will throw a std::bad_alloc
, which is derived from std::exception
and will enter the first branch. The other one, throw std::string
will enter the second branch. How can I check the object that was thrown? I tried with a catch(void*)
in the hopes to catch any object in memory, but that did not happen, so how can I find out what was thrown and from there debug what may have caused this?