Re: Why shouldn't we catch class RuntimeException?
manivannan.palanichamy@gmail.com wrote:
Good programming practice assumes that you have already validated
However, /great/ programming practice assumes nothing and protects against
everything. Least of all does it assume one's own perfection as a programmer.
input data, and as well written [sic] 'catch' to catch what can probably go
wrong at runtime.
But that's exactly what I'm saying. Catch the runtime exceptions, where
reasonable. Of course, I mean to say use a "well-written 'catch'".
One cannot list out all the million possible scenarios of failure at runtime. Thats why, almost every possible
'worse' is already defined under 'Checked Exceptions'.
Statistical assertions need statistical evidence. "Almost every"?
Anything that falls out of the 'Checked Exception' category is 'too worse' -- thats
RuntimeException. Your code should terminate as soon as the 'too
worse' (RuntimeException) happens.
A Web app likely should not terminate, but restore the user to a part of the
app not subject to the bug so that they continue and so that the million other
concurrent users don't suddenly lose their sessions for no apparent (to them)
reason.
But, who stops us, from handling the 'too worse'? :-) If one has the
stamina, then can very well catch up the RuntimeException!
I don't know what stamina has to do with it. I suggest one do the analysis
and program for the relevant situations. Sometimes those situations involve
catching RuntimeExceptions; whether they do or not is revealed through the
analysis.
--
Lew