Catching OutOfMemoryError

Posted by dotsid on Stack Overflow See other posts from Stack Overflow or by dotsid
Published on 2010-04-20T23:11:57Z Indexed on 2010/04/20 23:13 UTC
Read the original article Hit count: 644

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:

  1. is there any real word scenarios when catching java.lang.OutOfMemoryError may be a good idea?
  2. 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.

© Stack Overflow or respective owner

Related posts about java

Related posts about outofmemoryexception