Index: [thread] [date] [subject] [author]
  From: Owen L. Astrachan <ola@news.cs.duke.edu>
  To  : 
  Date: 26 Apr 1999 20:48:51 GMT

Re: instanceof

In article <Pine.SOL.3.91.990426163532.29382B-100000@teer23.acpub.duke.edu>,
Michael Abernethy  <mna@duke.edu> wrote:
>
>As I try to eliminate all our instaces of instanceof, I have thought of a 
>couple of ways to get around using this.  Most of these are hacks around 
>the problems, but was wondering if the following would be considered a hack.
>
>instead of using instanceof, just calling the fuction we want like
>
>(SuperClass).doSomething()
>
>and then catching the ClassCastException
>
>would this still be considered a hack, or is this now suddenly legitimate 
>good code?
>
>Mike Abernethy


Exceptions  should not be used in place of control-code, e.g., in place of
appropriate if statements.  In this case you haven't removed the
instanceof check, you've just removed the syntax of if instanceof..., the
check is still there (what causes the exception --- (! instanceof ...) )

Of course many people use exceptions to control execution.  But they're
wrong.  And of course I'm not evaluating your programs.

I. Ma Lurker



Index: [thread] [date] [subject] [author]