TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Java’s Checked Exceptions Are Just Weird Union Types

1 pointsby ekiauhceabout 2 years ago

1 comment

jfengelabout 2 years ago
Sure. Anybody who&#x27;s ever written in an exception-less language has created those &quot;ValueOrError&quot; types, and then dealt with the confusing morass of if-else statements.<p>They&#x27;re &quot;just&quot; union types, plus a syntax that puts the happy path of your code front and center. It&#x27;s not mandatory in a language. It&#x27;s a convenience for programmers to draw a strong distinction between the primary path of the code and the billions of ways that it can go wrong.<p>Checked exceptions are a compromise between putting the error condition on a conceptual par with the success condition, and completely ignoring the possibility of error (the way unchecked exceptions allow you to do). That middle position lets the compiler help you out: you need to acknowledge that the error is a possibility, and you can either just let it cascade up or catch it and try to recover.<p>So yeah, that puts it in the same conceptual position as the return type of the code.