Can i catch OutOfMemoryError in onMessage() method?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ajay_khatri
Posted On:   Monday, May 17, 2004 12:38 AM

I have a consumer, it receiving messages from a queue in onMessage() method. Every message is processed and stored in a Collection. I'm catching OutOfMemoryError error in onMessage() method but sometime it caught in try-catch block and some time its not the code is like this- public void onMessage(Message msg) { try{ //some processing //hashmap.put(msg,anObject); }catch(OutOfMemoryError err){System.out.println("error"+err);} } Actually i want that every time when there is an OutOfMemoryError condition it should be caught in try-catch block    More>>

I have a consumer, it receiving messages from a queue in onMessage() method. Every message is processed and stored in a Collection. I'm catching OutOfMemoryError error in onMessage() method but sometime it caught in try-catch block and some time its not


the code is like this-


public void onMessage(Message msg)


{


try{


//some processing


//hashmap.put(msg,anObject);


}catch(OutOfMemoryError err){System.out.println("error"+err);}


}


Actually i want that every time when there is an OutOfMemoryError condition it should be caught in try-catch block

   <<Less

Re: Can i catch OutOfMemoryError in onMessage() method?

Posted By:   Sean_Owen  
Posted On:   Monday, May 17, 2004 11:43 AM

This will always catch OutOfMemoryError, but if memory is actually exhausted, then you may trigger another OutOfMemoryError while handling the first one! That's why this may appear to not catch the error in all cases.



I would strongly advise you to not catch OutOfMemoryError, or other errors. You cannot meaningfully handle such an error; proceeding is dangerous. If you are running out of memory then either you are using too much memory and should find ways to reduce it, or you need more heap space / more physical memory!

About | Sitemap | Contact