Suppose there is a large Java application and I would like to gracefully shut it down if OutOfMemory error occurs. Now I see the following problems:
- Some components catch and "swallow" all
ThrowablesincludingOutOfMemory - If a thread does not catch
OutOfMemoryit exits and we do not know thatOutOfMemoryoccurred
Can I somehow register a "JVM-level" handler to catch any OutOfMemory, which may occur in the JVM?