• Post Reply Bookmark Topic Watch Topic
  • New Topic

catching java.lang.OutofMemoryException ?  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
catching java.lang.OutofMemoryException ?
We 'll find that it's almost never feasible to really catch it. By the time it's thrown, it's
likely that the situation is beyond repair and your JVM is going to
terminate.

thrown, the situation is likely beyond repair.

Then why api has provided mechanism to handle this exception ?
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By OutofMemoryException, do you mean OutOfMemoryError?

You have the facility to catch it the same way you have door handles inside a car which is travelling at 90mph. The door handles don't disappear when the car is moving, so you can still open the door and step out . . . but you don't
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good one .We may die if we take jump at that time
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you go back about 3 years on the Ranch (and search), there was somebody who had several lakh of objects in a List and was suffering OutOfMemoryErrors. He put code inside his catch(OutOfMemoryError) block to set most of the objects in that List to null, and they were deleted by the garbage collector, and his application continued to run.

But why didn't he set unneeded objects to null during the normal execution? That would be much better design.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!