C
Chris Smith
Java said:Dude, what's your prob?
I snipped your comments because they wrapped badly in my newsreader to
the point of being unreadable in the reply anyway, and I didn't want to
fix them. I admit that was a little lazy on my part, but I guarantee
you that it's not because I ignored them. Your comments said you don't
like ignoring the exception, but that you think it's cleaner than
writing a catch block to wrap in RuntimeException; that's exactly what I
was referring to.
I'm sorry if you're offended by my posts here. I see your advocacy of
ignoring exceptions as being extremely dangerous, and I'd like to
prevent people from taking that advice if at all possible. I have
nothing against you, but I do think (tempted to say *know*) that you're
mistaken on this point in a way that could have dire consequences.
I will restate the comment that, if you think there is the possibility that
MyException will be thrown, you cannot ignore it, and converting it to a
runtime exception is just as bad.
The problem, I think, is that we have differing definitions of
"possibility that MyException will be thrown". I agree completely that
if there is any situation where the current code, as written locally and
according to the specified behavior of any code it calls, might throw
that exception, then you should declare it as a checked exception. My
concern is what might happen with future modifications of the code.
It may be true, now, that super.myMethod will never throw MyException
from this context, as written. Nevertheless, it's easy to imagine
someone changing something about it's implementation, resulting in the
possibility that MyException will be thrown even with an instance of
Sub. Because Super's myMethod already declares MyException, the author
of the code may conclude that change to clients is not necessary, either
because the author doesn't understand all of the compatibility issues
with inheritance, or merely because the API is not considered fully
published (i.e., it's in-house, perhaps in a different module but not
provided as a third-party; in a situation where change control is
relaxed). In that case, the RuntimeException catches the error.
I still don't understand the statement that RuntimeException is just as
bad. Throwing a RuntimeException never potentially wipes out end-user
data. That's certainly one good thing about it.
I understand that you try to make a name for
yourself here and generate some consulting fees [...]
You're really sorta sounding like a troll here. I'm giving you the
benefit of the doubt... but when you show up and post anonymously in a
newsgroup for all of five days, give horrendously dangerous advice on
exception handling that contradicts all other respected sources of
information, and then start degrading a regular who has been posting
here for seven years by implying that I have hidden motives and am
trying to "make a name" for myself; well, let's just say that the doubt
of which you're getting the benefit is dwindling fast. The instant you
threaten to killfile Dale and Roedy as well, the doubt will be gone
entirely.
For the record, I don't take consulting work. I am employed full-time,
I like my job and plan to keep it for years to come, and my job doesn't
involve hiring myself out for consulting. MindIQ (my employer) does
offer training in Java software development and I generally teach it
when it's needed unless I'm otherwise committed, but I'm not here to
promote MindIQ's training, and I've been posting here for a lot longer
than I've been training for MindIQ.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation