terminate called after throwing an instance of C/C++ Origin: Application & API OSI layer 7 · Application Last updated 12 Oct 2026

C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check

A C++ exception wasn’t caught anywhere, so std::terminate aborted the program. what() tells you the reason.

Exact message you may see terminate called after throwing an instance ofwhat(): vector::_M_range_checkwhat(): stoi
Seen on: C/C++

Meaning

Frequent ones: std::out_of_range from .at(), std::invalid_argument from std::stoi on non-numeric text, std::bad_alloc for huge allocations, std::logic_error from basic_string constructed with nullptr.

Common causes

  • vector.at()/string.at() with an invalid index
  • std::stoi/stod on invalid input
  • Allocation failure (bad_alloc)
  • No try/catch around code that throws

⚡ Quick fix

  1. Validate indices and input before calling
  2. Catch the specific exception where you can recover
  3. Run in a debugger with catch throw to find the source

Detailed fix by platform

C++

  1. cpp
    try {
        int n = std::stoi(input);
    } catch (const std::invalid_argument&) {
        std::cerr << "not a number\
    ";
    }

How to diagnose

  1. Type — Exception class and what()
  2. Source — gdb: catch throw

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0xC0000005 — The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation (Windows)0xC00000050xC0000142 — The application was unable to start correctly (0xc0000142) (Windows)0xC0000142ArithmeticException — java.lang.ArithmeticException: / by zero (Java)ArithmeticExceptionAssertion failed — C/C++: Assertion `x > 0' failed. Aborted (core dumped) — assert() condition was false (C/C++)Assertion failedattempted to access privacy-sensitive data without a usage description — This app has crashed because it attempted to access privacy-sensitive data without a usage description (iOS)attempted to access p…Could not cast value of type — Swift: Could not cast value of type 'X' to 'Y' (iOS)Could not cast value …double free or corruption — C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped) (C/C++)double free or corrup…dyld: Library not loaded — dyld: Library not loaded: @rpath/X.framework/X — Reason: image not found (crash on launch) (iOS)dyld: Library not loa…terminate…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.