Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java exception handling

Reply
Thread Tools

java exception handling

 
 
polaris
Guest
Posts: n/a
 
      01-01-2008
i was arguing with my manager about whether it's better to throw
exception from a service that im developing or to give the user
returned value. My supporting points are:
1-thowing exception is much mostly than returned value in term of
performance.
2-in returned value way the user can customize the behavior of the
system as he like and he would have clear view of the service result.
3-with respect to the user requirement he doesn't really need a
returned value or exception from
the service.
my manager supporting points:
1-the service should be general so in future if somebody want to be
informed by the result of
the service we don't have to modify it.
but infact if we consider all the assumption we will delf into hunders
of assumptions and if this is nessary the returned value is better way
than throwing exception.

im very sorry for my long plah plah plah

any one have a comment.

Note: code in java
 
Reply With Quote
 
 
 
 
Arne Vajhj
Guest
Posts: n/a
 
      01-01-2008
polaris wrote:
> i was arguing with my manager about whether it's better to throw
> exception from a service that im developing or to give the user
> returned value. My supporting points are:
> 1-thowing exception is much mostly than returned value in term of
> performance.
> 2-in returned value way the user can customize the behavior of the
> system as he like and he would have clear view of the service result.
> 3-with respect to the user requirement he doesn't really need a
> returned value or exception from
> the service.
> my manager supporting points:
> 1-the service should be general so in future if somebody want to be
> informed by the result of
> the service we don't have to modify it.
> but infact if we consider all the assumption we will delf into hunders
> of assumptions and if this is nessary the returned value is better way
> than throwing exception.


I think exceptions has a couple of advantages over return value
error indication:

1) You can force the programmer to deal with it by making
the exception checked.

2) If the exception is not to be handled by the calling method,
then exceptions is much easier to get bubbling up through the
call stack than return values.

And performance should not be a problem. Exceptions should be
an exception !

Arne
 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      01-01-2008
polaris wrote:
> i was arguing with my manager about whether it's better to throw
> exception from a service that im developing or to give the user
> returned value. My supporting points are:
> 1-thowing exception is much mostly than returned value in term of
> performance.


The impact of try-catch blocks when they are not used has become
negligible and the performance impact is not terrible when they are
used. But any performance gained is on the order of several machine
cycles, which is not enough to impact such a major architecture decision.

> 2-in returned value way the user can customize the behavior of the
> system as he like and he would have clear view of the service result.


But values may be in imperfect states. A lazy user might not realize
that failures could happen and important code could blow up in his face.

> 3-with respect to the user requirement he doesn't really need a
> returned value or exception from
> the service.


If something is wrong, he needs to know. Period, full stop, end of story.

> my manager supporting points:
> 1-the service should be general so in future if somebody want to be
> informed by the result of
> the service we don't have to modify it.
> but infact if we consider all the assumption we will delf into hunders
> of assumptions and if this is nessary the returned value is better way
> than throwing exception.


How so? I sense some C or C++ assumptions coming into play here.

2. An exception can force the user to deal with the error. The user is
often in the best seat to decide whether or not he should repair the
situation or forcibly terminate.

3. Exceptions can provide finer granularity control over errors. Imagine
if Class.getMethod simply returned null instead of throwing an
exception. It would be difficult to tell if it was because the method
didn't exist or if it was merely insufficient access, the difference
between which may be important.

4. Hijacking the return values makes chaining operations difficult.
Class.forName(className).getMethod(name, args); is a somewhat common
idiom for code needing reflection. Should forName return null on error,
I would have to check for nullity first.

You also have not fully described what the circumstances are. In
general, the Java API often provides a good role model to follow. The
only times where it uses return values is where failure is not
exceptional, e.g., adding a method to a Set.

> im very sorry for my long plah plah plah


The proper term I believe is "pontification."

> any one have a comment.


One nit: try to use some more capitalization and spacing between
paragraphs. It's easier on eyes.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-01-2008
Joshua Cranmer wrote:
> [several good arguments for exceptions]

....
> You also have not fully described what the circumstances are. In
> general, the Java API often provides a good role model to follow. The
> only times where it uses return values is where failure is not
> exceptional, e.g., adding a method to a Set.


Joshua shows that exceptions are often, but not always, the best idiom for
things that seem to go either way.

Stepping back, Joshua's excellent advice is rooted in a perspective that
distinguishes "in-line" returns from "out-of-line" conditions that belong to
exceptions.

This part of domain analysis is fuzzy at times, no question. What really is
an "in-line" result in the problem domain?

One must factor predictions of which idiom will prove more troublesome to
maintain in the future. Notice that Joshua's answer is also grounded in the
notion of operational usefulness - what mechanism makes it easier to keep a
system running in the field?

There is a conceptual ground and a pragmatic basis that both argue for his
conclusions.

The consideration of future use is the hardest but also most important part of
planning an architecture. With a Really Useful Application, the operational
phase is the longest and most critical part of the life cycle.

--
Lew
 
Reply With Quote
 
polaris
Guest
Posts: n/a
 
      01-02-2008
On 1 , 18:53, Joshua Cranmer <Pidgeo...@verizon.invalid> wrote:
> polaris wrote:
> > i was arguing with my manager about whether it's better to throw
> > exception from a service that im developing or to give the user
> > returned value. My supporting points are:
> > 1-thowing exception is much mostly than returned value in term of
> > performance.

>
> The impact of try-catch blocks when they are not used has become
> negligible and the performance impact is not terrible when they are
> used. But any performance gained is on the order of several machine
> cycles, which is not enough to impact such a major architecture decision.
>
> > 2-in returned value way the user can customize the behavior of the
> > system as he like and he *would have clear view of the service result.

>
> But values may be in imperfect states. A lazy user might not realize
> that failures could happen and important code could blow up in his face.
>
> > 3-with respect to the user requirement he doesn't really need a
> > returned value or exception from
> > the service.

>
> If something is wrong, he needs to know. Period, full stop, end of story.
>
> > my manager supporting points:
> > 1-the service should be general so in future if somebody want to be
> > informed by the result of
> > *the service we don't have to modify it.
> > but infact if we consider all the assumption we will delf into hunders
> > of assumptions and if this is nessary the returned value is better way
> > than throwing exception.

>
> How so? I sense some C or C++ assumptions coming into play here.
>
> 2. An exception can force the user to deal with the error. The user is
> often in the best seat to decide whether or not he should repair the
> situation or forcibly terminate.
>
> 3. Exceptions can provide finer granularity control over errors. Imagine
> if Class.getMethod simply returned null instead of throwing an
> exception. It would be difficult to tell if it was because the method
> didn't exist or if it was merely insufficient access, the difference
> between which may be important.
>
> 4. Hijacking the return values makes chaining operations difficult.
> Class.forName(className).getMethod(name, args); is a somewhat common
> idiom for code needing reflection. Should forName return null on error,
> I would have to check for nullity first.
>
> You also have not fully described what the circumstances are. In
> general, the Java API often provides a good role model to follow. The
> only times where it uses return values is where failure is not
> exceptional, e.g., adding a method to a Set.
>
> > im very sorry for my long plah plah plah

>
> The proper term I believe is "pontification."
>
> > any one have a comment.

>
> One nit: try to use some more capitalization and spacing between
> paragraphs. It's easier on eyes.
>
> --
> Beware of bugs in the above code; I have only proved it correct, not
> tried it. -- Donald E. Knuth


ok I agree with you Arne and Joshua that exception forces the
programmer to deal with the result but one thing I have to clarify, is
that this services is provided to a department where they don't
really care about the result of this service at business level. In
fact it concerns the service provider himself who needs to know when
some action is happening in the this department to perform some action
useful for him.

Anther thing i have to mention is that we have more than 1700 expected
daily transactions on this service so we may give the performance
factor more attention even its negligible at the level of single
transaction.

exception involves extra code and processing while in reality we don't
need even any returned
value from the service.

alot of Thanks for u.
 
Reply With Quote
 
polaris
Guest
Posts: n/a
 
      01-02-2008
On 1 يناير, 18:14, Arne Vajhøj <a...@vajhoej.dk> wrote:
> polaris wrote:
> > i was arguing with my manager about whether it's better to throw
> > exception from a service that im developing or to give the user
> > returned value. My supporting points are:
> > 1-thowing exception is much mostly than returned value in term of
> > performance.
> > 2-in returned value way the user can customize the behavior of the
> > system as he like and he *would have clear view of the service result.
> > 3-with respect to the user requirement he doesn't really need a
> > returned value or exception from
> > the service.
> > my manager supporting points:
> > 1-the service should be general so in future if somebody want to be
> > informed by the result of
> > *the service we don't have to modify it.
> > but infact if we consider all the assumption we will delf into hunders
> > of assumptions and if this is nessary the returned value is better way
> > than throwing exception.

>
> I think exceptions has a couple of advantages over return value
> error indication:
>
> 1) You can force the programmer to deal with it by making
> * * the exception checked.
>
> 2) If the exception is not to be handled by the calling method,
> * * then exceptions is much easier to get bubbling up through the
> * * call stack than return values.
>
> And performance should not be a problem. Exceptions should be
> an exception ! *
>
> Arne- إخفاء النص المقتبس -
>
> - عرض النص المقتبس -


 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-02-2008
polaris wrote:
> ok I agree with you Arne and Joshua that exception forces the
> programmer to deal with the result but one thing I have to clarify, is
> that this services is provided to a department where they don't
> really care about the result of this service at business level. In
> fact it concerns the service provider himself who needs to know when
> some action is happening in the this department to perform some action
> useful for him.


How does this affect the issue of whether to use exceptions?

> Anther thing i have to mention is that we have more than 1700 expected
> daily transactions on this service so we may give the performance
> factor more attention even its negligible at the level of single
> transaction.


How does this affect the issue of whether to use exceptions?

> exception involves extra code and processing while in reality we don't
> need even any returned
> value from the service.


How does this affect the issue of whether to use exceptions?

Exceptions are not "extra" code. "Extra" code is code not needed. Exceptions
are code that is needed. Therefore, not "extra".

What is this laziness on the part of programmers, that they do not wish to
code the logic the problem at hand requires?

Correctly used, exceptions help the programmer of the application. They
aren't there to help the user, except indirectly in that the user will never
see the crashes prevented by the use of exceptions.

So the question with exceptions is whether you want to prevent the user from
experiencing program crashes. If you do wish to prevent the user from
experiencing program crashes, then exceptions are a powerful tool for that.

--
Lew
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-03-2008
polaris wrote:
> On 1 يناير, 18:14, Arne Vajhøj <a...@vajhoej.dk> wrote:
>> And performance should not be a problem. Exceptions should be
>> an exception !
>>
>> Arne- إخفاء النص المقتبس -
>>
>> - عرض النص المقتبس -

>


Say what ?

Arne
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-03-2008
polaris wrote:
> ok I agree with you Arne and Joshua that exception forces the
> programmer to deal with the result but one thing I have to clarify, is
> that this services is provided to a department where they don't
> really care about the result of this service at business level. In
> fact it concerns the service provider himself who needs to know when
> some action is happening in the this department to perform some action
> useful for him.


Does not change anything.

> Anther thing i have to mention is that we have more than 1700 expected
> daily transactions on this service so we may give the performance
> factor more attention even its negligible at the level of single
> transaction.


1700 daily transactions is absolutely nothing when we talk overhead
of exceptions.

If we assume that 1 million exceptions per second is 100% load, then
1700 exceptions per day is approx. 0.000002% extra load.

I think you can live with that.

> exception involves extra code and processing while in reality we don't
> need even any returned
> value from the service.


I think you need it.

Arne
 
Reply With Quote
 
Wojtek
Guest
Posts: n/a
 
      01-03-2008
Arne Vajhøj wrote :
> polaris wrote:
>> On 1 يناير, 18:14, Arne Vajhøj <a...@vajhoej.dk> wrote:
>>> And performance should not be a problem. Exceptions should be
>>> an exception !
>>>
>>> Arne- إخفاء النص المقتبس -
>>>
>>> - عرض النص المقتبس -

>>

>
> Say what ?
>
> Arne


That would be:

what say

--
Wojtek


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
python list handling and Lisp list handling Mark Tarver Python 22 04-26-2009 09:36 PM
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
SoapExtension for Global Exception handling; but prevent exception from propagating!! VSK ASP .Net Web Services 0 07-29-2003 05:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57