When the new operator fails to allocate memory, C++ throws a bad_alloc exception. The bad_alloc exception type is defined in the new header file, so any program that attempts to catch this exception should have the following directive:
try
{
// Code that uses the new operator
}
catch (bad_alloc)
{
// Code that responds to the error
}
No comments:
Post a Comment