Question: when jvm runs out of memory?
Answer: The JVM will throw an OutOfMemoryError , and in most cases, crash. Such an error is a Throwable, meaning it can be caught, and you can use such a catch block to (possibly) let your program fail gracefully.