-
-
Notifications
You must be signed in to change notification settings - Fork 251
Document the new exception API #1046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,15 +130,15 @@ You may use `try / catch` or `switch` to handle exceptions during async executio | |
```res | ||
// For simulation purposes | ||
let authenticate = async () => { | ||
raise(Exn.raiseRangeError("Authentication failed.")) | ||
JsError.RangeError.throwWithMessage("Authentication failed.") | ||
} | ||
|
||
let checkAuth = async () => { | ||
try { | ||
await authenticate() | ||
} catch { | ||
| Exn.Error(e) => | ||
switch Exn.message(e) { | ||
| JsExn(e) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still a little confusing where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just updated this page so it stays in sync with the new API, I think this could be improved in another PR. |
||
switch JsExn.message(e) { | ||
| Some(msg) => Console.log("JS error thrown: " ++ msg) | ||
| None => Console.log("Some other exception has been thrown") | ||
} | ||
|
@@ -152,14 +152,14 @@ You may unify error and value handling in a single switch as well: | |
|
||
```res | ||
let authenticate = async () => { | ||
raise(Exn.raiseRangeError("Authentication failed.")) | ||
JsError.RangeError.throwWithMessage("Authentication failed.") | ||
} | ||
|
||
let checkAuth = async () => { | ||
switch await authenticate() { | ||
| _ => Console.log("ok") | ||
| exception Exn.Error(e) => | ||
switch Exn.message(e) { | ||
| exception JsExn(e) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this exhaustive? How does this work with the other built-in exceptions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already covered in the exceptions page, I fear we would repeat ourselves too much otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is one of looking at it, but there you assume your user has read that exceptions page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nojaf you're totally right, I'd just change this a subsequent PR, I just replaced the calls to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Paul! |
||
switch JsExn.message(e) { | ||
| Some(msg) => Console.log("JS error thrown: " ++ msg) | ||
| None => Console.log("Some other exception has been thrown") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are
JsError
andJsExn
the same thing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JsError
is the module around JS errors whileJsExn
is the module around things that can be thrown and caught in JS, so pretty much anything actually.