Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: grammar fixes for clarity

...

Unchecked exception classes such as Error and its subclasses are not subject to compile-time checking not only because it is tedious to account for all exceptional conditions and , but also because recovery is generally difficult. However, even if when recovery is impossible, the Java Virtual Machine (JVM) allows a graceful exit and a chance to at least log the error. This is made possible by using a try-catch block that catches Throwable. Also, when code must not leak avoid leaking potentially sensitive information, catching Throwable is permitted. In all other cases, catching Throwable is not recommended. Where cleanup operations such as releasing system resources are possible, code should use a finally block within which the resources should be released or use a try-with-resources statement.

...

Note that this solution catches Throwable in an attempt to handle the error and ; it is an exception to ERR08-J. Do not catch NullPointerException or any of its ancestors.

...

In the event of actually running out of memory, it is likely that something some program data will be in an inconsistent state. Consequently, and it might be best to restart the process. If an attempt is made to carry on, reducing the number of threads, or just cycling them, may be a good idea because threads often leak memory.

The methods Thread.setUncaughtExceptionHandler() and ThreadGroup.uncaughtException() can be used to help deal with an OutOfMemoryError in threads.

...