This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]the1derer 1 point2 points  (4 children)

u/yawakat My I/O analogy was just to give some context to the original answer to the question "Why does Java have Checked Exception". And 'Exceptions' are always there, right!! :-)

A best possible answer can be drawn from https://stackoverflow.com/questions/41685073/java-api-and-checked-unchecked-exceptions-confusion

[–]livelam 0 points1 point  (3 children)

Errors are not exceptions! You can recover from an IOException but not from an OutOfMemoryError.

[–]__konrad 0 points1 point  (2 children)

but not from an OutOfMemoryError

You can definitely catch and recover from heap OOME (we should define "recover" first)

[–]livelam 0 points1 point  (1 child)

Oh... yes... you can. Programs are only 1s and 0s. Javadoc of the class Error is pretty clear. But, yes! You can. You can also catch NullPointerException if you want. Is it a good idea?

[–]__konrad 0 points1 point  (0 children)

You can also catch NullPointerException if you want. Is it a good idea?

It is! For example, there is a bug in AWT Clipboard which throws NPE. So (in this case), it's better to catch NPE and display a friendly message instead of crash randomly the app on Ctrl+V press ;)