Re:Code Design Decision – Always throw custom exceptions
by TedDoesntTalk on Monday December 19, 2022 @04:36PM
(#34058096)
I mean, can't you just catch Throwable (base class) and be done with it?
Re:Code Design Decision – Always throw custom exceptions
by layer8 on Monday December 19, 2022 @06:29PM
(#34059359)
This forces client code to handle arbitrary exceptions and it loses the information about which specific exceptions are actually thrown. This is like having Object as the return type on all functions, and having callers do instanceof to see what type of result they got. Exceptions should be part of the semantic contract of functions/methods just like return types are.
Re:Code Design Decision – Always throw custom exceptions
by zaphar on Monday December 19, 2022 @07:22PM
(#34059832)
Exceptions are a return type of functions. They return via a different path but there is no possible way you could disagree that they are a form of return.
Re:Code Design Decision – Always throw custom exceptions
by layer8 on Monday December 19, 2022 @07:28PM
(#34059885)
Exactly my point?
Re:Code Design Decision – Always throw custom exceptions
by dllthomas on Tuesday December 20, 2022 @11:24PM
(#34076611)
I understood it to be intended as agreement with emphasis.
Re:Code Design Decision – Always throw custom exceptions
by dllthomas on Tuesday December 20, 2022 @11:31PM
(#34076667)
As they don't return to the same place, don't return to a single place, and may (if not caught) not actually return but instead take down the entire thread, I think it's reasonable that for some purposes it might well make sense to treat exceptions as something other than "a form of return." ¯\_(ツ)_/¯
However we're treating them, however, I agree that they are a part of the interface and should be documented (and, where relevant, checked) as such.
Re:Code Design Decision – Always throw custom exceptions
by int_19h on Wednesday December 21, 2022 @02:58AM
(#34077879)
The point is that the type system doesn't properly reflect that. You should be able to declare a generic method that takes some T, and throws everything that T.foo() throws, for example.
If the type system were more capable, they'd just be equivalent to typed generic error returns, which work fine.