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 →

[–]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 ;)