We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If you got the server testing error this is the solution, I put a static value to preserve a counter and throw the exception of bad allocation when is a big number.
`
static int a;
try {
if (A > 1073741823) {
a++;
throw std::bad_alloc();
}
cout << Server::compute(A, B) << endl;
if (T == 0) {
cout << Server::getLoad() + a<<endl;
return 0;
}
}catch(std::bad_alloc &e)
{
cout<<"Not enough memory"<<endl;
if (T == 0) {
cout << Server::getLoad() + a<<endl;
return 0;
}
}
catch (std::exception &e) {
cout <<"Exception: " << e.what() << endl;
if (T == 0) {
cout << Server::getLoad() + a <<endl;
return 0;
}
}catch(...)
{
cout<<"Other Exception"<<endl;
if (T == 0) {
cout << Server::getLoad() + a <<endl;
return 0;
}
}`
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Exceptional Server
You are viewing a single comment's thread. Return to all comments →
If you got the server testing error this is the solution, I put a static value to preserve a counter and throw the exception of bad allocation when is a big number. `