Standard_MultiplyDefined

Diagnostic signature

Standard_MultiplyDefined

In Open CASCADE Technology, Standard_MultiplyDefined is a C++ exception thrown when an attempt is made to bind or define an element using a key that already exists in a context requiring strict uniqueness, such as within an NCollection_DoubleMap.

What it means

The Standard_MultiplyDefined diagnostic represents a C++ exception in the Open CASCADE Technology (OCCT) framework. It acts as a runtime assertion against uniqueness constraint violations. When an operation attempts to register, bind, or define an entity using a key or identifier that is already known within the given scope or data structure, this exception is raised. In OCCT's fundamental collection classes, it signifies that a new element cannot be added because its associated primary or secondary key is already bound to another entry, thus violating the strict one-to-one or unique-key requirements of the underlying container.

Why it happens

This exception is most commonly triggered by calling the Bind method on certain OCCT bidirectional mapping collections—most notably NCollection_DoubleMap—when either the primary key (Key1) or secondary key (Key2) is already present in the active map. Because a double map guarantees a strictly one-to-one bidirectional mapping between two distinct sets of keys, inserting a pre-existing key without explicitly removing its prior association violates the container's structural invariant. The underlying map implementation detects the existing key during the insertion attempt and explicitly raises the Standard_MultiplyDefined exception to prevent silent data corruption or ambiguous bindings.

Minimal reproduction

#include <NCollection_DoubleMap.hxx>
#include <Standard_MultiplyDefined.hxx>
#include <iostream>

int main() {
    NCollection_DoubleMap<int, int> myDoubleMap;
    // Initial binding of the key-value pair (1, 100)
    myDoubleMap.Bind(1, 100);

    try {
        // Attempting to bind a key that already exists in the double map
        myDoubleMap.Bind(1, 200);
    } catch (const Standard_MultiplyDefined& e) {
        std::cerr << "Caught exception: " << e.DynamicType()->Name() << std::endl;
        return 1;
    }

    return 0;
}

How to fix it

Guard insertion operations by checking if the keys are already bound, and conditionally unbind existing elements before re-binding to prevent uniqueness violations.

```C++
#include <NCollection_DoubleMap.hxx>
#include <Standard_MultiplyDefined.hxx>
#include <iostream>

int main() {
    NCollection_DoubleMap<int, int> myDoubleMap;
    myDoubleMap.Bind(1, 100);

    // Check if Key1 is already bound before attempting to bind or re-bind
    if (myDoubleMap.IsBound1(1)) {
        // Safely remove the existing mapping to maintain uniqueness
        myDoubleMap.UnBind1(1);
    }

    // Bind the new value without throwing Standard_MultiplyDefined
    myDoubleMap.Bind(1, 200);

    return 0;
}
```

Step 1

Step 2

Step 3

Upstream references

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

OCCT NCollection_DoubleMap.hxx Source