Checked Exceptions as an annotation #45884
Labels
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
devexp-pkg-meta
Issues related to package:meta
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
I never understood the hate checked exceptions get. The solution people give for why you don't need them is either if something went wrong
return null
which since null safety is a thing you get forced to handle but that doesn't tell me why something went wrong!The solution proposed for this is usually some kind of
Result
Object telling wether or not the request was a success as well as more information as to why it failed. This is all fine and good until you have multiple requests and all of them give you aResult
. You now have to write code like the following:The same kind of long and repetitive if has to be written if the function just returns null in case of an error.
If the function threw a checked exception I would be informed that I need to handle the exceptions and one
try {} catch {}
would solve the problem. This syntax would be way more readable and easier to maintain in my opinion.Maybe instead of adding checked exceptions as a language feature which has been decided is something dart will not do (See dart-lang/language#984)
Maybe we could add the feature as an annotation? If I could declare my function with an
@Throws(SomeException)
annotation and then get analyzer support that would already be a huge help since one could just configure the rule to act as an error.Originally posted by @DevNico in dart-lang/language#984 (comment)
EDIT: Community poll on Reddit
The text was updated successfully, but these errors were encountered: