RE: Introspect whether setCharacterEncoding is present..

<[email protected]> Wed, 13 Oct 2004 03:48:44 +0530
Newsgroups gmane.comp.java.advanced-servlets
Message-ID <[email protected]>
First of all, nice to see this list active again, with something other than Job offerings (otherwise referred to as Spam). Even if it is about something as offtopic as the proper use of Exceptions. (More like Basic-Coding-Practices, no?)

Also, nice to see Nic back to form again. For a while there, I'd been wondering if he'd actually learnt the art of tact...

 

(Sorry if this mail is HTML, my web-based mail client doesn't allow me to control that aspect, and also, apologies about the disclaimer at the end. Can't do much about it.)

Now, it's my turn to jump into the fray -

> > Use booleans and ifs. Unless it is in a non-critical path, then do
> > whatever you like. However, in a non-critical path, one may write how bad
> > code one desires, as it'll execute very seldom.

> Rubbish. You can't use booleans and ifs to do non-local exits.


No one said anything about non-local exits. The point is that using Exceptions for Critical Paths is not such a good idea. (And yes, I _have_ heard your argument against that too). They make your code harder to read. And it _is_ nice to think about that poor guy supporting your code a year from now, who'll be up at 4 a.m., manually parsing log files to trace through all these exceptions being thrown, looking for something related to Database connection errors. 400 lines? Well...

I do think that Exceptions and Non-local Exits are synonymous. But that still doesn't make them a _preferred_ way of doing things. You should only use a non-local exit, when the situation warrants it.


> Sometimes an application has a critical path that

> requires non-local exits.

Yes, but was the example that triggered this entire debate one of those? Admitted, it's the only obvious way to check if the class exists in the current JVM, but Class.forName() is really intended to get an instance of a class if you expect it to be there, and not as a mechanism to check if the class exists.

The fact that the Java standard API doesn't give you a better way to check for the existence of a class without throwing an exception (it doesn't, right? Just checking.) does NOT make the suggested way, The _Right_ Way. It just makes it a convenient hack to get around the limitations of the existing API - also known as, The Only Way.

 

What is a "non-local exit"? What is an "If" check? And what is the requirement here? All we're looking for, is the existence of a class.

An Exception - (like the dictionary meaning of the word) - should be used only when things don't go as expected. When you break a rule. So, Exceptions are expected to be thrown less often than not thrown. If the code is being written to support 2.2 containers, then Exceptions are going to be thrown more often than not, then maybe we're not really doing the right thing.

 

> But then I'm happy to give people an argument about why goto is not a bad thing.

Right. You really _really_ don't like support engineers, do you? (No, I'm not a support engineer either, but I like to think of myself as the sensitive type)

 

And as far as the performance aspect goes, I don't disagree with Nic there. Most times, the effect of throwing Exceptions, on performance, is negligible.

 
Looking forward to the new list.
 
RJA
http://rja.blogspot.com <http://rja.blogspot.com>  
 

	-----Original Message----- 
	From: Nic Ferrier [mailto:[email protected]] 
	Sent: Tue 10/12/2004 11:35 
	To: [email protected] 
	Cc: 
	Subject: Re: [advanced-servlets] Introspect whether setCharacterEncoding is present..
	
	


	=?iso-8859-1?Q?Endre_St=F8lsvik?= <[email protected]> writes:
	
	> |
	> | - 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.
	>
	> longjump or not - that's NOT the question! They have to be allocated, and
	> -filled in-. That is the problem. Not the control flow as such.
	
	Yes... but everything has to be allocated. The jmp_buf in C has to be
	alloced. There is still a cost in C. Java is about making allocation
	easier, not more expensive. It's actually de-allocation that costs
	more than it does in C and the cost is amortized over the life of the
	VM.
	
	
	> | - there is no other non-local exit feature
	> |   Unlike in C++ which still has longjmp left over from C.
	>
	> Use booleans and ifs. Unless it is in a non-critical path, then do
	> whatever you like. However, in a non-critical path, one may write how bad
	> code one desires, as it'll execute very seldom.
	
	Rubbish. You can't use booleans and ifs to do non-local exits.
	
	Sometimes an application has a critical path that requires non-local
	exits.
	
	
	> The time it takes to =make the Exception=, which wasn't mentioned in your
	> list!
	
	The reason it wasn't in the list is that it's not a factor. All
	allocation has roughly equal cost.
	
	
	--
	Nic Ferrier
	http://www.tapsellferrier.co.uk



[Non-text portions of this message have been removed]



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