Re: Introspect whether setCharacterEncoding is present..

Endre Stølsvik <[email protected]> Tue, 12 Oct 2004 16:56:50 +0200 (CEST)
Newsgroups gmane.comp.java.advanced-servlets
Message-ID <Pine.LNX.4.44.0410121651250.26253-100000@excalibur.intra.coretrek.com>
On 12 Oct 2004, Nic Ferrier wrote:

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

An Exception is "heavy to make" - its a) an Object, b) a big Object (!),
c) have this awfully long (in Tomcat, at least!) StackTrace to be
generated and filled in (I mean, its a ton of strings, numbers, whatevers,
that need to be fetched off of the stack, and loaded into some internal
representation..)

One should, in my opinion, definately avoid throwing Exceptions in any
"critical paths" of a system. This also goes for 'return codes': the
normal "exit values" should be integers, Strings, whatevers, and -not-
Exceptions..

|
| Exceptions are NOT just for errors they are a real language feature in
| Java, not an afterthought.

Well, they can be used for many nice things, but I'd also say that they
should be avoided in the critical paths of any program.

But for this specific check, one could do it once, then store the result:
it is pretty obviously not going to change after start!

| The fact that exceptions capture the stack in the form of a trace is
| also fantastically useful.

That is very true, and extremely useful in logging (log4j). But just check
out a verbose debug-log of an application with and without "location info"
in log4j (with location-info, it throws an internal exception for
stack-tracing) - that is one huge difference.

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

I definately think it is, when in critical section.. But not -that- bad,
it should just be cached for optimum performance.

Endre



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/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/