One of my class variables is a 2D array. The size depends on the user input. The user may input size which may exceed his hardware limit. So I want to handle this properly. Is the following code correct?
int counter;
try
{
int size = 20000;//this is actually from user input
array = new double*[size];
for(counter = 0; counter < size; counter++)
array[counter] = new double[size];
}
catch(std::bad_alloc)
{
try
{
for(int i = 0; i < counter; i++)
delete[] array([i]);
delete[] array;
array = NULL;
//display limitation message
size = 2;
array = new double*[size];
for(int i = 0; i < size; i++)
array[i] = new double[size];
}
//catch again & exit application
}