Re: Introspect whether setCharacterEncoding is present..

Nic Ferrier <[email protected]> 12 Oct 2004 15:24:20 +0100
Newsgroups gmane.comp.java.advanced-servlets
Message-ID <[email protected]>
luca <[email protected]> writes:

> Nic Ferrier wrote:
> >>I am no expert in this field, but I've always heard that Exceptions
> >>are for exceptions and not for flow of control (not only is it
> >>a problem of style, but also performance, I hear)
> > 
> > 
> > Where did you hear that?
> > 
> 
> http://www.javapractices.com/Topic19.cjp
> 
> There is a misconception  - especially popular among C programmers
> migrating to Java  - that exceptions can be used to define ordinary
> control flow. This is a misuse of the idea of exceptions, which are
> meant only for exceptional conditions.

This is guff. Is James Gosling going to come round and slap me? I
don't think so.

Exceptions are sometimes *necessary* for control flow. Consider a
multi-method FSM for example. How would you do that except by using
exceptions? Yet that would be using them for control flow.

I don't know where this comes from. It's a very stupid statement.


> a search on google will give you many more:
> 
> http://www.google.no/search?hl=no&q=java+exceptions+flow+control&meta=

I can find just as many people who say that it's okay as say that it's
bad.

Let's look at the facts:

- exceptions are non-local exits

- java has syntax for throwing them and catching them

- there is a readability cost to throwing them
  Similar problem to the use of goto.

- there is a computation cost to throwing them 
  Though exceptions are often highly optimized, depsite what some people
  in that google search seem to think. This is because most VMs are
  written in C and an exception can be implemented as a
  longjmp. Certainly, unix longjmp's are very fast.

- there is no other non-local exit feature
  Unlike in C++ which still has longjmp left over from C.


So what is it about the above that means that exceptions should not be
used for control flow?

Is it just because someone decided that exceptions should not be used
for control flow? Because if that's the case you can carry on writing
programs your way and I'll write good ones  /8->



Nic


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

Before posting a question, try to find your answer here: 
<http://www.egroups.com/links/advanced-servlets>
Announcements should go to: [email protected]
To Post a message, send it to: [email protected]
To Unsubscribe, send a blank message to: [email protected] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/advanced-servlets/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/