4 ms·
Does any other language than Java has the throws keyword to declare exceptions?
In Java you can do something like this:
public boolean DoSomething() throws CustomEdgeCase {
....
}
The compile tells me what exceptions I need to handle and so makes sure I do not forget about some edge cases.
This is not possible in e.g. C# or TypeScript.
I wonder why? I find it very helpful to ensure software quality??
Am I wrong or why is this not adapted elsewhere?
Best Regards,
Oliver
working on https://www.monsterwriter.app/
- vegai_ 5y agoHere's some hyperbole to help understand the issue: https://phauer.com/2015/checked-exceptions-are-evil/ https://phauer.com/2015/checked-exceptions-are-evil/
- WolfOliver 5y agoNice, thank you for the link! I guess the last statement of the article summarizes the problematic: > At the beginning you feel safer with them, but later they prevent you from swimming quickly. IMO: When I want to swim quickly, I go for dynamic typed languages [1]. Most enterprises choose a static typed system to be save and ensure some quality while having a hight fluctuation and a diverse level of skills. [1] I'm also much more used to dynamic typed languages (Ruby & Javascript)
- speedgoose 5y agoC++ has it of course. But it’s a bad practice.
- TheMonarchist 5y agoChecked exceptions were deprecated in C++11 and removed in C++17. Now there's just noexcept to declare that no exceptions will propagate to call site. The feature was always opt-in anyway. The compiler has always just assumed that anything can throw everything, unless informed otherwise.
- WolfOliver 5y agoA discussion on checked exceptions in TypeScript: https://github.com/microsoft/TypeScript/issues/13219 https://github.com/microsoft/TypeScript/issues/13219
- smt88 5y agoSeems silly to force you to declare it when the compiler and static analysis could easily find it in the method body automatically. Exceptions aren't supposed to be valid output, so declaring them in a method signature is just a messy way of creating typed errors. I prefer the Go way (a Maybe object) better.