Re: Introspect whether setCharacterEncoding is present..

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

> Charles Forsythe wrote:
> 
>  >  You could set a
> > Context Attribute (or other flag) based on the following test:
> > 
> >         try {
> >             Class.forName("javax.servlet.http.HttpServletRequestWrapper");
> >             // This is Servlet API >= 2.3 --> Set Attribute/Flag TRUE
> >         } catch(ClassNotFoundException cnfx) {
> >             // This is Servlet API < 2.3 --> Set Attribute/Flag FALSE
> >         }
> 
> 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?

Exceptions are actually a restricted form of a more general control
structure called a continuation. Continuations can be thrown up the
stack but also down the stack. They do the latter by stack capture.

Anyway, I don't see anything wrong with using exceptions for control
features. Exceptions are, after all, only a long jump, a non local
exit.

Exceptions are NOT just for errors they are a real language feature in
Java, not an afterthought. The fact that exceptions capture the stack
in the form of a trace is also fantastically useful.


In Charles' specific example the catch is being used to handle a
an exception in exactly the right way, it's an exception based
assertion mechanism.


I'm very surprised anyone thinks this is bad style. It isn't.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk


------------------------ 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/