This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Exceptions v/s return values
Posted by Amol Deshmukh on October 17, 2000 at 3:16 AM
Thanks Amit for your help. The design section was indeed
of great help in helping me decide between exception and
return values. :)
But still i have another query - what is the impact of using
Exceptions on the memory. I mean is there any overhead involved
in using exceptions? If so how exactly does throwing an
exception cause an overhead.
I know the query seems a bit off track, but i would be glad if
anyone could help.
> Hi Amol.
> Pls check out the topic Designing with Exceptions in
> the design section. I think that will answer your query.
> Thanks & regards,
> > Hi.
> > Pls pardon for a slightly large post.
> > I have a design related query regarding whether to use
> > exceptions or return values. I mean how does one decide
> > or what are the factors that would help one decide whether
> > to go for Exceptions or Return values.
> > Sometimes it is not possible to use return values to
> > indicate error condition like say u return int and all
> > possible int values are valid return values. Then you go
> > for throwing exception to indicate an error condition. But
> > at other times maybe all int values are not valid return
> > values so that you go for returning a non-standard int value
> > that indicates an error condition.(Classic example of this
> > case is the function String.indexOf("somestring") which
> > returns -1 to indicate search string not found.)
> > It is such cases where i am not sure whether to go for
> > using return values or exceptions. Is there any overhead
> > involved in using exceptions as compared to return values?
> > Also another factor in my mind that may influence the choice
> > is the fact that Exceptions have the ability to return more
> > information wrapped inside the exception object where as
> > return values cant do that.
> > I'd like to have a definitive answer on this though, and any
> > comments on the same would be greatly appreciated.
> > Thanks,
> > Amol Deshmukh
> > Cognizant Technology Solutions,
> > Pune,
> > India