Sealed Types vs Exceptions?

David Alayachew davidalayachew at gmail.com
Tue Dec 5 00:05:32 UTC 2023


Hello Amber Dev TeaM,

I learned a lot about Exceptions in the previous discussion above, so I
figured I'd ask this question as well -- when does it make sense to handle
exceptional cases via a Sealed Type (DivisionResult ====> Success(double
answer) || DivideByZero()) vs an Exception (DivideByZeroException)?

The only difference I can see is that an Exception gives you debugging
details (line number, stack trace) that would be very difficult for a
Sealed Type to attain. And if that is the key difference, doesn't that sort
of imply that we should opt into the more info-rich source of information
wherever possible? After all, debugging is hard enough and more info is to
everyone's benefit, right?

And most of the extra info is static (line numbers don't change). I'll
avoid performance as a reason, as I don't understand the mechanics of what
makes one faster or slower.

Thank you all for your time and help!
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20231204/3b86fce0/attachment-0001.htm>


More information about the amber-dev mailing list