Implement JSG_TRY / JSG_CATCH macros #6021
Merged
+338
−42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement JSG_TRY / JSG_CATCH macros
Add new macros for exception handling in JSG code that automatically convert
both JavaScript exceptions (JsExceptionThrown) and KJ exceptions (kj::Exception)
to jsg::Value. This enables cleaner exception handling syntax and prepares for
future coroutine support with co_await on jsg::Promise.
The implementation uses a JsgCatchScope helper class that sets up a v8::TryCatch
on construction and converts caught exceptions via catchException(). The macros
use the "goto-dead-else-branch" pattern from KJ_TRY/KJ_CATCH for clean syntax.
Usage: