Catching java.lang.OutOfMemoryError
- by dotsid
Documentation for java.lang.Error says:
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch
But as java.lang.Error is subclass of java.lang.Throwable I can catch this type of throwable.
I understand why this is not good idea to catch this sort of exceptions. As far as I understand, if we decide to caught it, the catch handler should not allocate any memory by itself. Otherwise OutOfMemoryError will be thrown again.
So, my question is:
is there any real word scenarios when catching java.lang.OutOfMemoryError may be a good idea?
if we catching java.lang.OutOfMemoryError how can we sure that catch handler doesn't allocate any memory by itself (any tools or best practicies)?
Thanks a lot.