Return to site

☕🎓JAVA CERTIFICATION QUESTION: catch block

· java,ocp

Which of the following classes should be avoided from being caught in a catch block?

* ArrayIndexOutOfBoundsException

* IOException

* NoSuchClassCastError

* NullPointerException

* OutOfMemoryError

* StackOverflowError

#java #certificationquestion #ocp

 

Java Exception classes can be caught in a catch block.

However, it's generally not recommended to catch Error classes like OutOfMemoryError or StackOverflowError

because they typically indicate serious problems in the JVM that are not recoverable.

It's better to let the JVM handle such errors.

Note that NoSuchClassCastError does not exist.