FAQ: Why doesn't Wing allow functions to declare exceptions thrown #843
Replies: 1 comment
-
In Java, when a method explicitly declares an exception it throws in its signature, it's called a checked exception. When a method on a class declares a checked exception, then anyone else calling that method must handle that exception (e.g. by calling it within a try/catch block) or else they get a compile time error. (If you wanted to annotate thrown exceptions just for informational purposes and without any changes to language semantics, you could always just use docstrings in Wing). I think checked exceptions are a clever idea for improving code safety, but some leading programming language designers such as Anders Hejlsberg (the lead architect of TypeScript and C#) think they're problematic. Kotlin (a language pretty well respected variation of Java) also describes in their docs why they don't have checked exceptions: https://kotlinlang.org/docs/exceptions.html#checked-exceptions. I haven't read their arguments in full, so perhaps there's still an argument for including it in Wing -- but I'd reckon we should consider the historical pushback against checked exceptions to understand if any of the issues would still apply to our language. |
Beta Was this translation helpful? Give feedback.
-
A question that comes up from time to time regarding Wing language design is why isn't Wing allowing function signatures to declare thrown exceptions (like Java, for example)?
Context: Wing error handling, as defined in the language spec
Beta Was this translation helpful? Give feedback.
All reactions