Description
Change Intent
Enable an optional way for communicating that exceptions can happen by extending the function definition with the phrase "throws exception":
// Signaling that this function might throw an exception.
// Tooltips in IDEs coudl be extended to highlight this.
void myFunc() throws exception {
throw Exception("something went wrong");
}
Currently:
void myFunc() { //no signaling whatsoever that this function might throw an exception
throw Exception("something went wrong");
}
An IDE might propose a Quick-Fix when "throws exception" is not present in the function definition although the function might throw an exception.
(Though I personally prefer the sound of "raises exception" but "throws exception" is probably better suited since the keyword throw
is used in the dart language.)
Justification
Without any digging there is no way of knowing whether a function might throw an error or not. Having (1) a program running unexpectedly into an error or (2) encapsule "just in case" everything in a try-catch block and say "sorry, an unexpected error has occured" is fatal in the first case and is at least no good practice in the second case.
Especially for new programmers or even experienced ones using new packages this would be really helpful.
Impact
Anyone could see at a glance if a function might throw an exception. Having this information would massively improve stability and usabilty of programs in general. Making this feature optional also means that any progammer can decide to use it. I would suggest to make the IDE point out a missing "throws exception" and offer a quick fix.
Mitigation
No response
Change Timeline
No response
Associated CLs
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status