OpenCascade.js

Exception classes

OCCT exception class hierarchy and the JS-side getExceptionMessage helper.

OCCT throws subclasses of Standard_Failure. Inside the wasm module, every throw becomes a WebAssembly.Exception instance whose payload is the C++ object. The OCJS bindings expose:

  • The exception class hierarchy via bound classes (oc.Standard_Failure, oc.Standard_OutOfRange, etc.).
  • getExceptionMessage(error) — a helper that decodes a WebAssembly.Exception into the OCCT failure text.

Hierarchy

Standard_Failure
├── Standard_OutOfRange
├── Standard_NullObject
├── Standard_NoSuchObject
├── Standard_TypeMismatch
├── Standard_DomainError
├── Standard_DivideByZero
└── Standard_ProgramError
    └── Standard_NotImplemented

Every subclass surfaces a GetMessageString() and inherits the What() method returning a static identifier.

getExceptionMessage(error)

Named export of @taucad/opencascade.js. Accepts a WebAssembly.Exception and returns a string.

import init, { getExceptionMessage } from '@taucad/opencascade.js';

try {
  riskyOcctCall();
} catch (error: unknown) {
  if (error instanceof WebAssembly.Exception) {
    console.error('OCCT failure:', getExceptionMessage(error));
    return;
  }
  throw error;
}

What about JS-side Error.message?

WebAssembly.Exception.message is empty for C++-thrown values. The real message lives in C++ memory and must be reached through the helper above.

On this page