Reputation: 20890
One of my tasks is eating up too much memory and failing with an OutOfMemoryError exception. Can I catch that exception? Can I get a warning when I'm about to run out of memory?
Upvotes: 2
Views: 174
Reputation: 1247
You can catch the OutOfMemoryError. However, its not recommended.
There are a bunch of reasons why the error occurs, the most obvious one being http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/OutOfMemoryError.html. You also have reasons like 98% of GC time is spent in reducing less than 2% of Heap etc.
As for a call back before OutOfMemoryError, there is no such thing.
Upvotes: 2