-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Counter proposal : type safe try/catch #43
Comments
@nicolo-ribaudo indeed it is! the syntax feels a bit odd to me because of those 2 reasons:
Alternatively, having: try {
cons res = await fetch("https://api.example.com/data")
return validationSchema.parse(
await res.json()
)
}
when RequestError catch (err) {
handleRequestError(err)
} ...could also work, but idk, |
“on” is a word that’s associated with event listeners and observables; i don’t think that makes sense. The pattern matching proposal may add an |
@ljharb i don't have strong opinion on it. the difference imho, is in where the keyword is located. with |
What about Python-like style try {
cons res = await fetch("https://api.example.com/data")
return validationSchema.parse(
await res.json()
)
}
except RequestError (error) { } |
The proposal seems copying Golang famous
value, _ := blah()
but I think we can do better in error handling if we copied dart/java instead.Considering the 1st example:
I would rather leverage a new
on XXX catch (err)
instead which would look like this:Advantages over your proposal:
EDIT: this addresses your concerns about nested try/catch
EDIT2: would consider also
rethrow
as a syntaxic sugar ofthrow err
, that'd be nice but it's not really inside the proposalThe text was updated successfully, but these errors were encountered: