Open CASCADE Standard_RangeError

Diagnostic signature

Standard_RangeError

`Standard_RangeError` is a C++ exception thrown by Open CASCADE Technology (OCCT) when an index accesses a collection or mathematical structure outside its defined bounds.

What it means

The `Standard_RangeError` diagnostic is a standard C++ exception raised by Open CASCADE Technology (OCCT) data structures when an application attempts to access an element using an index that is outside the permitted bounds. It serves as a strict bounds-checking safeguard, ensuring that read and write operations on vectors, matrices, arrays, and other mathematical or geometric containers remain safely within the explicitly allocated limits for those entities. OCCT enforces this check at runtime, frequently via the `Standard_RangeError_Raise_if` macro inside element accessors (such as `operator()`), immediately halting execution to prevent silent memory corruption or undefined behavior.

Why it happens

The exception is triggered when an index passed to a container's access operator evaluates to a value strictly less than the container's initialized lower bound or strictly greater than its upper bound. A prevalent cause in OCCT applications is the incorrect assumption that indexed structures always start at zero. For example, structures such as `math_Vector`, `math_Matrix`, and `NCollection_Array1` allow arbitrary index ranges to be defined upon instantiation (e.g., `math_Vector(1, 3)`), but they conventionally default to a lower bound of 1. If an application attempts to access index 0 of a 1-based vector, the bounds check injected by `Standard_RangeError_Raise_if` natively catches the violation and throws the exception. Beyond container bounds, querying geometric properties (e.g., invoking `IsCN` on a curve) with invalid inputs like a negative continuity parameter can also manually raise this exact error.

Minimal reproduction

#include <math_Vector.hxx>
#include <Standard_RangeError.hxx>
#include <iostream>

int main() {
    try {
        // Create a math vector with an explicit arbitrary range of [1, 3]
        math_Vector aVec(1, 3);
        
        // Attempt to access index 0, which is outside the defined range
        aVec(0) = 2.0;
        
    } catch (const Standard_RangeError&) {
        std::cerr << "Caught Standard_RangeError: Index out of bounds." << std::endl;
    }
    return 0;
}

How to fix it

Interrogate the `Lower()` and `Upper()` boundaries of the OCCT data structure dynamically to ensure loop indices and accessors stay within the allocated, arbitrarily defined index range.

```C++
#include <math_Vector.hxx>
#include <Standard_RangeError.hxx>
#include <iostream>

int main() {
    try {
        // Create a math vector with an explicit arbitrary range of [1, 3]
        math_Vector aVec(1, 3);
        
        // Access the elements using the valid lower and upper bounds dynamically
        for (Standard_Integer i = aVec.Lower(); i <= aVec.Upper(); ++i) {
            aVec(i) = 2.0 * i;
        }
        
    } catch (const Standard_RangeError&) {
        std::cerr << "Caught Standard_RangeError: Index out of bounds." << std::endl;
    }
    return 0;
}

```

Step 1

Step 2

Step 3

Step 4

Upstream references

Open CASCADE Technology OCCT 7.8.0 — Standard_RangeError.hxx — retrieved 2026-08-11

math_Vector.hxx (OCCT 7.8.0 Source)

Foundation Classes (OCCT Wiki)