Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created March 21, 2012 12:04
Show Gist options
  • Save lamprosg/2146487 to your computer and use it in GitHub Desktop.
Save lamprosg/2146487 to your computer and use it in GitHub Desktop.
C++/Qt out of memory exceptions & handling
QApplication app(argc, argv);
...
try
{
app.exec();
}
catch (const std::bad_alloc &)
{
// clean up here, e.g. save the session
// and close all config files.
return 0; // exit the application
}
//*******************OR*****************************************************//
x = new (std::nothrow) X(); // Class X
if (x == NULL) //or: "if (x==0)", NULL pointer
{
// allocation failed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment