Exceptional Server

  • + 0 comments

    Your entire comment :

    if (T == 0) { cout << Server::getLoad() + a<<endl; why this is used can anyone explain?
    

    If the bad_alloc exception is thrown then the Server::compute() call is not made for test case T and the Server::load value is not incremented and the last line of output will be wrong. To workaround this problem, the static variable a is used to keep count of how many test cases this happens and when T reaches zero, the value of a is added to the value returned by Server::getLoad() in order to print the corrected value on the last line of output. Furthermore, the statement return 0; causes the main block to exit, preventing in the protected code, the call to Server::getLoad() and the printing of its returned value.