[HN Gopher] Better Error Handling
___________________________________________________________________
Better Error Handling
Author : zdgeier
Score : 7 points
Date : 2025-04-20 20:13 UTC (2 hours ago)
(HTM) web link (meowbark.dev)
(TXT) w3m dump (meowbark.dev)
| teddyh wrote:
| > _Lack of Type System Integration_
|
| Well, IIUC, Java had (and still has) something called "checked
| exceptions", but people have, by and large, elected to not use
| those kind of exceptions, since it makes the rest of the code
| balloon out with enormous lists of exceptions, each of which must
| be changed when some library at the bottom of the stack changes
| slightly.
| remexre wrote:
| I think it's fair to say that having some sort of syntactically
| lightweight sum or union type facility makes this way nicer
| than anything Java ever had -- subclassing isn't really a
| solution, because you often want something like:
| type FooError = YoureHoldingItWrong | FileError type
| BarError = YoureHoldingItWrong | NetworkError fn foo()
| -> Result<int, FooError> { ... } fn bar() ->
| Result<int, BarError> { ... } fn baz() ->
| Result<String, BarError> { ... }
|
| TypeScript's type system would hypothetically make this pretty
| nice if there were a common Result type with compiler support.
|
| Rust needs a bit more boilerplate to declare FooError, but the
| ? syntax automatically calling into(), and into() being free to
| rearrange errors it bubbles up really help a lot too.
|
| The big problem with Java's checked exceptions was that you
| need to list all the exceptions on every function, every time.
| domlebo70 wrote:
| Very balanced post thank you. Often these posts tout an approach,
| and never consider downsides.
___________________________________________________________________
(page generated 2025-04-20 23:00 UTC)