Unchecked Exception List
ArrayIndexOutOfBoundsException
ClassCastException
IllegalArgumentException
IllegalStateException
NullPointerException
NumberFormatException
AssertionError
ExceptionInInitializerError
StackOverflowError
NoClassDefFoundError
Checked Exception List
Exception
IOException
FileNotFoundException
ParseException
ClassNotFoundException
CloneNotSupportedException
InstantiationException
InterruptedException
NoSuchMethodException
NoSuchFieldException
Unchecked Exception List
ArrayIndexOutOfBoundsException
ClassCastException
IllegalArgumentException
IllegalStateException
NullPointerException
NumberFormatException
AssertionError
ExceptionInInitializerError
StackOverflowError
NoClassDefFoundError
Checked Exception List
Exception
IOException
FileNotFoundException
ParseException
ClassNotFoundException
CloneNotSupportedException
InstantiationException
InterruptedException
NoSuchMethodException
NoSuchFieldException
Assume the below are java.lang unless I specify otherwise:
- Casting: ClassCastException
- Arrays: ArrayIndexOutOfBoundsException, NullPointerException
- Collections: NullPointerException, ClassCastException (if you're not using autoboxing and you screw it up)
- IO: java.io.IOException, java.io.FileNotFoundException, java.io.EOFException
- Serialization: java.io.ObjectStreamException (AND ITS SUBCLASSES, which I'm too lazy to enumerate)
- Threads: InterruptedException, SecurityException, IllegalThreadStateException
- Potentially common to all situations: NullPointerException, IllegalArgumentException
You would do well to look at Java site's Package Summary pages. Here's one: https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/io/package-summary.html
Videos
Many a blog post has been written about how Checked Exception are bad/the devil incarnate.
For all the bloviating about how bad it is, most of these articles and their comment sections lack any concrete alternatives.
For Java versions before 21, there simply doesn't seem to be a reasonable (never mind close to standardized) alternative to express that a method returns Thing or AException or BException.
For Java 21+, with sealed classes and exhaustive switches, you kind of can manually recreate a vague resemblance of e.g. Rusts Result Type. That will still lack some necessities, like enforcing checking the Error for Void methods (as in Result<Void, Err>).
So my question is:
If you agree that checked exceptions are bad, what alternative are you actively using right now?
How is your favorite library handling this? Because most still seem to use exceptions
Personally, I'm getting reaaaallly annoyed by the way people talk about exceptions online. For one, they'll point out a problem, but then fail to demonstrate a solution that wouldn't have it. For another, there's very little will, it seems, to suggest and work towards a serious alternative. How can we, as a community, warn against using a builtin feature for an important part of programming without providing alternatives? Aren't we simply screwing over newbies with these takes?