Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/detail/legacy-module-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Flow:
9. On not-found: retry with absolute path for `node:`/`cloudflare:` prefixed specifiers.
10. Final fallback: throw `"No such module"` error.

Errors are handled via `js.tryCatch`: exceptions are caught, and
Errors are handled via `JSG_TRY/JSG_CATCH`: exceptions are caught, and
Comment thread
jasnell marked this conversation as resolved.
`js.v8Isolate->ThrowException()` is called to schedule them on the isolate
(V8 requires exceptions to be scheduled, not thrown as C++ exceptions, during
resolve callbacks).
Expand Down
8 changes: 8 additions & 0 deletions src/workerd/jsg/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class MyType: public jsg::Object {
- `TypeHandler<T>&` as trailing param gives manual conversion access
- Compat flags param on `JSG_RESOURCE_TYPE` gates members conditionally

## Errors

Use `JSG_TRY(js) { ... } JSG_CATCH(exception) { ... }` to catch JS exceptions in
C++ code. The `js` is a `jsg::Lock&` parameter. The `exception` is a `jsg::Value`
containing the JS exception that was thrown.

The legacy `js.tryCatch(fn)` is deprecated and will be eventually removed.

## ANTI-PATTERNS

- **NEVER** opaque-wrap `V8Ref<T>` — use handle directly
Expand Down
Loading