Throw Js Erros constructor EvalError, RangeError, etc #6931
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.
After #6611 was merged it is no longer possible to throw errors like
EvalError. The throw statement now isthow new Error(exn).Example: The
Js.Exn.raiseEvalErrorfunction:https://github.com/rescript-lang/rescript-compiler/blob/0b1443f967808a41c3ad309002eca964f0b6465f/jscomp/others/js_exn.res#L48
compile to:
https://github.com/rescript-lang/rescript-compiler/blob/0b1443f967808a41c3ad309002eca964f0b6465f/lib/es6/js_exn.js#L10-L14
This PR add a function
throw:Side question
Here a question arises whether we should support
EvalErrorand others, or encourage ReScript exceptions. Recently documented the exceptions builtin (rescript-lang/rescript-lang.org#880)My idea is to use ReScript exceptions and not bindings to Js
Error(i.e@new external make: string => t = "Error"). We will still catch Js ErrorsRelated #6929