libcascade

Debugging wasm exceptions

Decode WebAssembly.Exception into actionable OCCT type and message text.

OCCT failures compiled with native WASM exception handling reach JavaScript as WebAssembly.Exception values. Decode them through the initialized runtime:

import oc from 'libcascade';

try {
  using fillet = new oc.BRepFilletAPI_MakeFillet(badShape);
  fillet.Shape();
} catch (error: unknown) {
  if (error instanceof WebAssembly.Exception) {
    const [type, message] = oc.getExceptionMessage(error);
    console.error(`${type}: ${message}`);
  } else {
    throw error;
  }
}

error.message is not the C++ failure text. The helper returns a [type, message] tuple such as ['Standard_Failure', 'BRepFilletAPI_MakeFillet: Empty argument'].

Common failures

Type or messageLikely cause
Standard_OutOfRangeIndex past an OCCT collection boundary
Standard_NullObjectMethod called through a null Handle<T>
Standard_TypeMismatchDowncast to the wrong TopoDS_* subtype
BRepAlgoAPI_*Invalid or self-intersecting boolean input
BRepFilletAPI_MakeFilletRadius too large or a degenerate edge

Debug builds

For source-level debugging, build with -g -fwasm-exceptions -O1 and use Chrome's WASM DWARF debugger.

On this page