In this HackerRank Exceptional Server problem in c++, we have a function that takes 2 large numbers as its input and returns a numeric result. Unfortunately, there are various exceptions that may occur during execution. complete the code in your editor so that it prints appropriate error messages, should anything go wrong.

HackerRank Exceptional Server in C++ problem solution

HackerRank Exceptional Server in C++ problem solution

 try {
            int res = Server::compute(A, B);
            cout << res << endl;
        } catch ( const std::bad_alloc& e ) {
            cout << "Not enough memory" << endl;
        } catch ( const std::exception& e ) {
            cout << "Exception: " << e.what() << endl;
        } catch ( ... ) {
            cout << "Other Exception" << endl;
        }