doc: suggest not to throw JS errors from C++#18149
Closed
joyeecheung wants to merge 3 commits intonodejs:masterfrom
Closed
doc: suggest not to throw JS errors from C++#18149joyeecheung wants to merge 3 commits intonodejs:masterfrom
joyeecheung wants to merge 3 commits intonodejs:masterfrom
Conversation
Also provide an example on how to use internal/errors to handle errors in C++.
targos
approved these changes
Jan 14, 2018
CPP_STYLE_GUIDE.md
Outdated
|
|
||
| A lot of code inside Node.js is written so that typechecking etc. is performed | ||
| in JavaScript. | ||
| Note that in general, type-checks on arguments should done in JavaScript |
maclover7
approved these changes
Jan 14, 2018
CPP_STYLE_GUIDE.md
Outdated
| throw errors.Error('ERR_ERROR_NAME', ctx.code); | ||
| } | ||
| return result; | ||
| } |
Contributor
There was a problem hiding this comment.
A nit: missing semicolon.
CPP_STYLE_GUIDE.md
Outdated
| const ctx = {}; | ||
| const result = binding.foo(str, ctx); | ||
| if (ctx.code !== undefined) { | ||
| throw errors.Error('ERR_ERROR_NAME', ctx.code); |
jasnell
reviewed
Jan 14, 2018
CPP_STYLE_GUIDE.md
Outdated
| A lot of code inside Node.js is written so that typechecking etc. is performed | ||
| in JavaScript. | ||
| Note that in general, type-checks on arguments should be done in JavaScript | ||
| before the arguments are passed into C++. |
Member
There was a problem hiding this comment.
Perhaps add something about including a CHECK at the C++ level?
starkwang
approved these changes
Jan 15, 2018
danbev
approved these changes
Jan 15, 2018
Member
Author
jasnell
approved these changes
Jan 15, 2018
cjihrig
approved these changes
Jan 15, 2018
TimothyGu
reviewed
Jan 16, 2018
| ### Avoid throwing JavaScript errors in nested C++ methods | ||
|
|
||
| When you have to throw the errors from C++, try to do it at the top level and | ||
| not inside of nested calls. |
Member
There was a problem hiding this comment.
"Maybe" mention Maybe<> and MaybeLocal<> as possible methods to pass exception status if exceptions have to be transported through nested C++ calls.
Member
Author
There was a problem hiding this comment.
Hmm I think we could make a separate section for the Maybes and link from here?
Member
Author
There was a problem hiding this comment.
@TimothyGu Since this was how it's documented prior to this PR, I'll open a separate PR for the usage of Maybes. We also need a section about using the Maybe APIs instead of the deprecated V8 APIs.
Member
Author
|
Landed in 27925c4, thanks! |
joyeecheung
added a commit
that referenced
this pull request
Jan 16, 2018
Also provide an example on how to use internal/errors to handle errors in C++. PR-URL: #18149 Refs: #18106 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
evanlucas
pushed a commit
that referenced
this pull request
Jan 30, 2018
Also provide an example on how to use internal/errors to handle errors in C++. PR-URL: #18149 Refs: #18106 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
MylesBorins
pushed a commit
that referenced
this pull request
Feb 27, 2018
Also provide an example on how to use internal/errors to handle errors in C++. PR-URL: #18149 Refs: #18106 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Also provide an example on how to use internal/errors
to handle errors in C++.
Refs: #18106
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
doc