-
Notifications
You must be signed in to change notification settings - Fork 213
Would Replacing LateInitializationError with LateInitializationException Be More Intuitive? #4029
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
Comments
Should not be allowed. It is an Error since they follow the definition of Error:
When specifying Exceptions are for situations which you can't predict like e.g. disk are full, bad network and so on. It should never be unexpected if a If your program are unpredictable when it comes to fields being set or not, then those fields must be defined as nullable so you, as a programmer, are forced to check if the field contains a value before using it. This pattern are much more safe and prevents the errors you are trying to handle in your example. |
Yes, now that I think about it, you're absolutely right. |
Not exactly what you are proposing, but #3680 would allow us to query for late variable initialization. I think this would enable you to do what you want. |
class Example {
late final String x;
}
main() {
Example example = Example();
try {
print(example);
} on LateInitializationError catch (e) {
x = "late init";
print(x);
}
}
This statement isn't working at the moment, but I feel like it should be allowed.
The text was updated successfully, but these errors were encountered: