Most common checked and unchecked Java Exceptions?

exception, java

Solution

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

Problem

As far as I understand, there is no way to find out which exceptions a method throws without looking up the API docs one-by-one. Since that is no option, I'd like to reverse the research and ask you which are the most common Exceptions and RuntimeExceptions you've come across when dealing with: - Casting - Arrays - Vector, ArrayList, HashMap, etc. - IO (File class, streams, filters, ...) - Object Serialization - Threads (wait(), sleep(), etc.) - or anything else that is considered "basic Java" I realize that this might be subjective and boring but it is for a class test and I really don't know better.

Original source