On a machine with memory issues my Java app kept crashing due to an OutOfMemoryError:
Exception in thread “Thread-1” java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
I started logging thread counts and memory usages and neither one was increasing/leaking. I tried to catch the ‘Exception’ as it was claiming but the app would still fail.
Finally I read the javadoc on the java.lang.OutOfMemoryError and discovered that the error inherits from Error and Throwable rather than Exception so I was not able to catch it. Catching the Throwable allowed me to keep my app going.