3 ms·
> the language lacks a “throws” statement I'm not sure what you mean by this? Python has the "raise" statement [0], which "throws" an error from within a funct
by BerislavLopac 2y ago
> the language lacks a “throws” statement
I'm not sure what you mean by this? Python has the "raise" statement [0], which "throws" an error from within a function or other code.
[0] https://docs.python.org/3/reference/simple_stmts.html#raise https://docs.python.org/3/reference/simple_stmts.html#raise
- silvester23 2y agoWhat they mean is that in Java, for example, a method has to explicitly state which exceptions it might throw as part of its signature. Note that they said "throws", not "throw". Python does not have that.
- BerislavLopac 2y agoAh, I understand now. Well, by default Python doesn't declare a return type either yet the tools are able to infer it in many cases; I see no reason why tools like mypy couldn't similarly infer the raised exception types as well. Plus, the typing annotations could presumably be expanded to include some notification to declare raised exception types explicitly.
- alex_suzuki 2y agoYes sure, but the raise statement is part of the implementation (like throw in Java), and not part of the signature (throws), which would presumably make it into a generated API documentation.
- valbaca 2y agoThey're talking about Java's Checked Exceptions: https://www.baeldung.com/java-checked-unchecked-exceptions https://www.baeldung.com/java-checked-unchecked-exceptions which are part of a method's declaration `void foo() throws KaboomException` The ironic thing is that Checked Exceptions aren't particularly well-loved in Java. For example, Kotlin (which is like Java++) did away with them.