And OutOfMemoryError
handled like any other exception:
- If he is caught, then nothing else happens.
- If it is not caught, it either processes threads or groups of topics , an exception handler for exception handlers. This almost always causes the thread to stop.
However, there are two factors that do not actually exist in the other exceptions:
OutOfMemoryError
- Error
, not Exception
. This means that it can hardly be caught anywhere: you should not try to catch Error
in general (with very few exceptions), and this is usually not done, so the chances of handling it are pretty low.- When an
OutOfMemoryError
occurs, and because of this the object cannot access the GC, you will still have a little memory, and most likely you will encounter the same problem again later.
And if the thread to which this happens is the only non-daemon thread (often, but not necessarily, the main thread that executes the main
method), then this thread, which kills, terminates the entire JVM (which is often perceived as " crash" ).
So tl; dr : it will probably kill the thread, and if the memory problem is not resolved, this can happen with a lot of threads.
source share