-
Notifications
You must be signed in to change notification settings - Fork 200
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
Sum throw types #1487
Comments
Is the request here a better syntax for catching different types, or to have some kind of static checking of thrown types like checked exceptions? If it's just the former, you can already have multiple void main() {
try {
/// This would have a return type of [String]
/// and a sum throw type of [BarException] or [BazException]
final result = throwsBarBaz('');
} on BarException catch (e) {
print('bar exception!');
} on BazException catch (e) {
print('baz exception!');
}
} The current syntax is actually even shorter than your proposal. :) If it's to have static checking of them, well there's #984. But that was closed because I think the world has generally decided that checked exceptions are a bad idea. |
Yes, this is for checked exceptions, so I will close in favor of #984 |
Related: #68 #349 #83
The ability to sum throw types for functions would make errors much more useful in Dart. In practice I see a lot of developers just not handle errors or go to great lengths to catch everything and rethrow them as an uber-error with a string enum and string message.
As I recall, Swift has the ability to sum error types, removing types that have been explicitly caught, and adding rethrow types in their place. This feature might look something like this in dart.
The text was updated successfully, but these errors were encountered: