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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. C++
  3. Classes
  4. Exceptional Server
  5. Discussions

Exceptional Server

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • skw1985
    3 years ago+ 7 comments

    Simple work around because bad_alloc is unreachable:

        try {
            if (A > 1073741823LL) {
                Server::compute(2, 1);
                throw bad_alloc();
            }
            cout << Server::compute(A, B) << '\n';
        }
        catch (bad_alloc &e) {
            cout << "Not enough memory\n";
        }
        catch (exception &e) {
            cout << "Exception: " << e.what() << '\n';
        }
        catch (...) {
            cout << "Other Exception\n";
        }
    
    21|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature