E.Otter wrote:
> I'm of the opinion that something like an "OutOfMemoryError" and just about
> any other thing that ends with "Error" should not be caught. Its not
> really a bug or problem in your code its a problem with the environment the
> program is running in. Let the user see the problem. Your code needs to do
> something and the user has a PC with either not enough memory or just too
> much stuff currently running. Your code can't fix it. The user needs the
> smack upside the head to get a better system or shut some junk down.
FWIW, I'm not of that opinion.
I recently wrote a GUI for an application: this application reads and
analyses loads of files. If the user tries to analyse too large a
system, then the application will run out of memory.
The problem is that when this OutOfMemoryError is thrown by the
application, if it's not caught, then the GUI will just hang. It won't
report the Error automatically. Thus the user waits for a while,
guesses something's gone horribly wrong, and rips it all down.
It's much better to throw up a warning dialog, telling him that the
universe is finished and he might as well give up.
Yes, I know: you cannot guarantee that there will be enough memory to
throw up the dialog, but I tried, nonetheless, and testing has shown
that the system will throw up the dialog 60% of the time. Yes, for the
other 40%, the user is just waiting for the bus that will never come;
but 60% is better than nothing.
Also, I've noticed that, even when there's no memory to throw up a
dialog, the JVM can always (apparently) do a System.out.println(); so I
do this, too. Unfortunately, most users will start the application by
double-clicking a jar file, in which case the println() sends the
message into deep space somewhere; but again: a little effort can *try*
to allieviate the user's frustration.
..ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition.