Created
March 21, 2012 12:04
-
-
Save lamprosg/2146487 to your computer and use it in GitHub Desktop.
C++/Qt out of memory exceptions & handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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