-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Suggestion: Checked & Unchecked Exceptions #23060
Labels
Duplicate
An existing issue was already created
Comments
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Scenario
Node.js introduced a
UnhandledPromiseRejectionWarning
to make developers aware of handling promise rejections. In the future, promise rejections that are not handled will terminate the Node.js process which will stop applications from continuing to function.Solution
When using code, it's hard to say if that particular code throws an exception or not. That's why I suggest to implement a concept similar to checked exceptions in Java. Checked exceptions need to get handled by the programmer with a
try/catch
block or athrows
clause. It would be great if TypeScript supports such a concept even for Promise-based code so that you can force developers to catch Promise rejections.Proposed Change
In the short term, it might be helpful if
tsc
detects whether a method is marked with @throws, so that the developer can be informed about error cases to handle when using such methods. This way, the change would not interfere with ES6 or ES7 syntax because it's limited to parsing comments in JavaScript.Code Sample
provider.ts
consumer.ts
The text was updated successfully, but these errors were encountered: