Jump to content
Excelsior Forums
Sign in to follow this  
chr1s

How do I suppress the "Uncaught Exception: Out of memory" dialog

Recommended Posts

My application occasionally encounters an OutOfMemoryError. This is due to having to extract the full-text from arbitrary documents using third party libraries, i.e. not something that I can easily fix, just a fact of life.

My application can easily recover from such OOMEs: the thread performing the extraction is killed, but right after it a lot of memory is again available. My application even contains code that measures the amount of memory that is left afterwards, in order to decide whether to inform the user about the OOME through a dialog or just log it and continue.

However, my JET-compiled application always shows a dialog with the message "Uncaught Exception: Out of memory". Given that I already have code for handling OOMEs, is there any way I can suppress this dialog?

I have read the discussion that led to this feature and I understand and agree with the arguments, but in my case it is a real nuisance.

Share this post


Link to post
Share on other sites

"Uncaught Exception" means that none of the methods in the call stack (including the run method) handled the exception.

Did you use a try-catch block in the run() method to let the thread die quietly?

Share this post


Link to post
Share on other sites

The thread does not catch that particular throwable. It currently does a "catch (Exception e)"  in the Thread.run method, but OutOfMemoryError is not an Exception.

I do have a Thread.UncaughtExceptionHandler registered in my main class that does handle all Throwables and that consumes the OOME when running my app in Eclipse. My assumption is therefore that JET already intervenes with this error dialog before the OOME reaches that handler, is that correct?

I will try catching all throwables in the thread that is typically causing the problem.

Share this post


Link to post
Share on other sites

I invoke Thread.setDefaultUncaughtExceptionHandler, that should do it, right?

FYI: the trick with catching the OutOfMemoryError inside the extraction thread worked flawlessly. These OOME's are now caught and logged and are no longer directly noticeable for the end user, all others OOME's are still caught by JET's interception mechanism and result in the error dialog. This is exactly how I want it to work.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×