Re: Overriden method doesn't throw Exception, super may.

From: Java Architect (danc_at_dynamicresolve.com)
Date: 07/12/04


Date: Mon, 12 Jul 2004 13:18:49 -0700


"Chris Smith" <cdsmith@twu.net> wrote in message
news:MPG.1b5c9793cb471793989704@news.altopia.net...
> Java Architect wrote:
> > Apologies. I finally realized what I was missing about the problem. I
> > haven't been ignoring you, I've actually been trying to understand the
> > problem. Now I think I do, and here is how I would handle it (using the
> > original code):
>
> Okay,
>
> > // Why not override this as well and bury the non-thrown exception
in
> > // the first place?
>
> Yes, that would be nice. Hasn't it already been mentioned in this
> thread? Nevertheless, as you recognize, it's just moving the problem.
>
> > public void myMethod() {
> > try { super.myMethod(); } catch (MyException ignore) {}
> > }
>
> Here, then, is where you solve the problem, and you do it by catching
> and ignoring the exception? This is pretty universally accepted as a
> really bad idea. Essentially, when things are so out of control that
> your basic assumptions are being violated, you choose to ignore it and
> continue as if nothing happened?
>
[SNIP]

Dude, what's your prob? You snipped my comments that say I don't like the
idea of ignoring the exception, and then try to blast me for it? The point
is, as has been pointed out, the exception is NEVER thrown because the
subclass doesn't throw it. There is an overriden 'other' method that CANNOT
throw the exception because it is not declared.

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 solution in that case would be to
create a checked exception class to throw and convert the MyException to
that so that the underlying implementation is hidden from the caller, but
the fact that an exception is thrown is not.

Converting to a runtime exception is just as bad an idea here as ignoring
the exception.

Now, if you want to dispute my solution, do it with my entire argument, not
a heinously distorted version. I understand that you try to make a name for
yourself here and generate some consulting fees, but that's no reason to try
to defend a mistake by misquoting someone who's only interest is providing
some help to the original poster. Congratulations, you've made my ignore
list.

> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation



Relevant Pages

  • Re: Only writing 1 byte to a file stream on one pc in office
    ... The OP has a finally block, not catch, so he isn't ignoring anything. ... His application-level exception handler will log any exception... ... checking his file cache I found that most of the files were only 1 byte ... FileStream fs = new FileStream(ImageLocation, FileMode.Create, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: FileSystemWatcher and Getting Access to a file
    ... the file until the exception goes away. ... and ignoring a particular exception. ... "Lebrun Thomas" wrote in message ... >> elegant solution to this problem rather than just "trying to continually ...
    (microsoft.public.dotnet.framework)
  • Re: Highway code section 114 (dazzle from vehicle lighting)
    ... handbrake MUST be applied EVERY time a car is staionary?..no matter ... exception to the rule then you will feel justified in ignoring it & ...
    (uk.rec.driving)
  • Re: Strange Audio Problem
    ... >Perhaps it is throwing an exception the code is ignoring. ... Exception and stacktraces them all just to be sure that it isn't the ... Could it be something else than an infinite loop? ... And the server and the test-program both runs on the same machine under ...
    (comp.lang.java.programmer)
  • Re: Validating file names
    ... running Novel, from your G: running Linux file system, from your H: running ... I am not saying one does not exist! ... file file and handle any exceptions that were thrown. ... If an exception is thrown then the specified ...
    (microsoft.public.dotnet.languages.vb)