emscripten-core / emscripten-core/emscripten

Allow catching JavaScript exceptions from C++

Open
#11,496 23 comments 3 reactions 0 assignees View on GitHub
embind
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Somewhat wider version of #11434, but applicable to synchronous functions as well: right now, even with exception handling enabled, there is no way to catch an exception from JavaScript call in C++ and extract its properties.

This means that things like DOMException can't be gracefully handled on C++ side or e.g. when integrating with C libraries where you want to convert different kinds of DOMException into different error codes.

I propose to make it possible to catch any JS exceptions and rethrow them on C++ side with Embind, so that things like

```cpp
try {
someValue.call("method");
} catch (val e) {
// ...handle val
}
```

would work and return a JS handle to the caught exception.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.