Open CASCADE Standard_OutOfRange Exception

Diagnostic signature

Standard_OutOfRange

An exception thrown by the Open CASCADE Technology (OCCT) geometry kernel when an index or parameter falls outside the valid bounds of a collection or geometric entity. This commonly occurs due to 0-indexing errors, as many OCCT collections dynamically define bounds and are conventionally 1-indexed.

What it means

Standard_OutOfRange is a C++ exception class within the Open CASCADE Technology (OCCT) framework that inherits from Standard_Failure. It signals a bounds-checking failure, indicating that an operation attempted to access a data structure (such as a dynamic array or sequence), curve, or surface using an index or evaluation parameter that exceeds the strictly defined lower or upper limits of that entity.

Why it happens

This diagnostic is most commonly caused by iterating over OCCT collections (such as NCollection_Array1, TColStd_Array1OfReal, or sequence variants) using standard C++ 0-based indexing habits. Unlike standard library containers (e.g., std::vector), many OCCT arrays dynamically define arbitrary lower and upper bounds and are historically 1-indexed by default (starting at index 1 and ending at N). Attempting to access element 0 via .Value(0) or iterating with an exclusive < Length() condition instead of inclusive bounds triggers this exception. Furthermore, it is explicitly thrown by Standard_OutOfRange_Raise_if macros when geometric intersection algorithms or curve evaluators receive a parameter that falls outside their restricted domain.

Minimal reproduction

#include <TColStd_Array1OfReal.hxx>
#include <iostream>

int main() {
    try {
        // Create an array with bounds 1 to 5 (1-indexed)
        TColStd_Array1OfReal myArray(1, 5);

        // Standard C++ 0-indexing habit triggers Standard_OutOfRange
        double val = myArray.Value(0);
        std::cout << val << std::endl;
    } catch (const Standard_OutOfRange& e) {
        std::cerr << "Caught exception: " << e.GetMessageString() << std::endl;
        return 1;
    }
    return 0;
}

How to fix it

Refactor array, sequence, and curve access operations to strictly query and utilize the entity's .Lower() and .Upper() bound methods instead of hardcoding 0 or assuming standard C++ container offset arithmetic.

```cpp
#include <TColStd_Array1OfReal.hxx>
#include <iostream>

int main() {
    // Create an array with bounds 1 to 5
    TColStd_Array1OfReal myArray(1, 5);

    // Initialize with values using dynamic boundary methods
    for (Standard_Integer i = myArray.Lower(); i <= myArray.Upper(); ++i) {
        myArray.SetValue(i, i * 1.5);
    }

    // Safely access values using bounds checking
    double val = myArray.Value(myArray.Lower());
    std::cout << "First value: " << val << std::endl;

    return 0;
}
```

Step 1

Step 2

Step 3

Step 4

Upstream references

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

foundation_classes · Open-Cascade-SAS/OCCT Wiki - GitHub