Standard_NegativeValue
Standard_NegativeValue is an OCCT exception raised when a geometric or topological algorithm receives a negative parameter for a quantity that must be strictly positive, such as a radius or offset distance.
In Open CASCADE Technology (OCCT), `Standard_NegativeValue` is an exception class that signals a bounds-checking failure when a geometric or topological algorithm is supplied with a negative value for a parameter that mathematically or physically requires a strictly positive (or non-negative) value. As part of OCCT's standard exception hierarchy, it is defined in the `Standard` package and operates as a subclass of `Standard_OutOfRange`. The exception acts as a critical runtime safeguard to prevent downstream geometric solvers from attempting to evaluate undefined or physically impossible shapes, such as inverted radii, negative lengths, or invalid tolerances.
The exception is actively thrown by OCCT boundary representation (BRep) modifiers and geometric construction solvers during input validation. When constructing parameterized geometry, dimensions such as radii, offsets, and distances cannot meaningfully evaluate to a negative space. For example, the topological 2D filleting algorithm `BRepFilletAPI_MakeFillet2d::AddFillet` raises this exception if it is instructed to build a fillet with a radius less than or equal to zero. Similarly, purely geometric solvers like `Geom2dGcc_Circ2d2TanRad` will throw `Standard_NegativeValue` if they are instantiated to compute tangent circles but are passed a negative target radius. The tool chain aborts the operation and emits this exception to avoid silent failures or corrupt geometric states.
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepFilletAPI_MakeFillet2d.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp_Explorer.hxx>
#include <gp_Pnt.hxx>
#include <Standard_NegativeValue.hxx>
#include <iostream>
int main() {
// 1. Create a simple planar face to apply a 2D fillet
BRepBuilderAPI_MakePolygon polygon;
polygon.Add(gp_Pnt(0.0, 0.0, 0.0));
polygon.Add(gp_Pnt(10.0, 0.0, 0.0));
polygon.Add(gp_Pnt(10.0, 10.0, 0.0));
polygon.Add(gp_Pnt(0.0, 10.0, 0.0));
polygon.Close();
TopoDS_Face planarFace = BRepBuilderAPI_MakeFace(polygon.Wire());
// 2. Extract the first topological vertex
TopExp_Explorer explorer(planarFace, TopAbs_VERTEX);
TopoDS_Vertex vertex = TopoDS::Vertex(explorer.Current());
// 3. Attempt to add a fillet with a negative radius
BRepFilletAPI_MakeFillet2d filletAlgo(planarFace);
try {
// Passing -5.0 triggers the Standard_NegativeValue exception
filletAlgo.AddFillet(vertex, -5.0);
} catch (const Standard_NegativeValue& e) {
std::cerr << "Caught OCCT Exception: " << e.GetMessageString() << std::endl;
return 1;
}
return 0;
}
Normalize dynamic parameters with std::abs and enforce strictly positive bounds prior to executing OCCT geometric operations.
```c++
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepFilletAPI_MakeFillet2d.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp_Explorer.hxx>
#include <gp_Pnt.hxx>
#include <Standard_NegativeValue.hxx>
#include <iostream>
#include <cmath>
int main() {
BRepBuilderAPI_MakePolygon polygon;
polygon.Add(gp_Pnt(0.0, 0.0, 0.0));
polygon.Add(gp_Pnt(10.0, 0.0, 0.0));
polygon.Add(gp_Pnt(10.0, 10.0, 0.0));
polygon.Add(gp_Pnt(0.0, 10.0, 0.0));
polygon.Close();
TopoDS_Face planarFace = BRepBuilderAPI_MakeFace(polygon.Wire());
TopExp_Explorer explorer(planarFace, TopAbs_VERTEX);
TopoDS_Vertex vertex = TopoDS::Vertex(explorer.Current());
BRepFilletAPI_MakeFillet2d filletAlgo(planarFace);
double inputRadius = -5.0;
// Fix: Validate and normalize the radius to a strictly positive value
double safeRadius = std::abs(inputRadius);
const double epsilon = 1e-7;
if (safeRadius > epsilon) {
try {
filletAlgo.AddFillet(vertex, safeRadius);
std::cout << "Fillet added successfully with radius: " << safeRadius << std::endl;
} catch (const Standard_NegativeValue& e) {
std::cerr << "Caught OCCT Exception: " << e.GetMessageString() << std::endl;
return 1;
}
} else {
std::cout << "Radius too small, skipping fillet construction." << std::endl;
}
return 0;
}
```
Open CASCADE Technology OCCT 7.8.0 — Standard_NegativeValue.hxx — retrieved 2026-08-11