I do a simple throw "TEST THROW" and it isn't caught in my catch (std::exception& e). Is it because I'm catching an std::exception& e? I mean, are only exception classes derived from std::exception caught? If not, am I doing something wrong or is it normal? By the way, none of the two catch blocks caught the throw exception.
int main()
{
try
{
throw "TEST THROW"; // TEST
Core core;
core.Init();
core.Load();
while (!core.requestCloseWindow)
{
core.HandleInput();
core.Update();
core.Draw();
}
core.Unload();
core.window->close();
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
try
{
time_t rawTime;
struct tm* timeInfo;
char timeBuffer [80];
time(&rawTime);
timeInfo = localtime(&rawTime);
strftime(timeBuffer, 80, "%F %T", timeInfo);
puts(timeBuffer);
std::ofstream ofs; // Pas besoin de close, car le destructeur le fait.
ofs.exceptions(std::ofstream::failbit | std::ofstream::badbit);
ofs.open("log.txt", std::ofstream::out | std::ofstream::app);
ofs << e.what() << std::endl;
}
catch (std::exception& e)
{
std::cerr << "An error occured while writing to a log file!" << std::endl;
}
}
return 0;
}
std::exception
, so the exception is not caught by the catch clause designed to catch objects of typestd::exception
. – Igor Tandetnike
be? – Raymond Chen