The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Exceptions



This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Exceptions and Performance

Posted by Dave Hunter on July 06, 1999 at 5:53 AM

> For me, this whole thing stemmed from reconstituting Objects after serialization. Some data members were declared transient (or didn't implement Serializable). So I was faced with the decision of cluttering up constructors with "initialization" methods, recreating the data members on readObject (directly or using the same "initialization" methods), wrapping their usage in a try/catch clause (looking for NullPointerExceptions) or just checking to see if the memebers != null. I opted for the try/catch (for better or worse) since the members really have one time that they were actually == null. So I guess the question is, "If I know that 99.999% of the time I will not throw an Exception, what is the cost of a try/catch clause?"
The method doit3() is of course more eficient than doit 1,2.
The cluttering up of a Constructor is probably preferable(better Performance) to cluttering up an entire class.
You could use the lazy inititialization idiom to reduce the clutter.

class MyClass {
MyObject myObj;
public MyClass(){
this.myObj = new MyObject();
//+"initialization clutter"

void doit3() {


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us