Connecting Tech Pros Worldwide Forums | Help | Site Map

how are exception expensive?

Monster
Guest
 
Posts: n/a
#1: Jul 22 '05
Are they expensive because of what happens when an exception is thrown or
because of the extra checking involved when you wrap exceptions around code?



John Carson
Guest
 
Posts: n/a
#2: Jul 22 '05

re: how are exception expensive?


"Monster" <monster@this.monster@that> wrote in message
news:hpOdnZWg4IsHFw3dRVn-uQ@giganews.com[color=blue]
> Are they expensive because of what happens when an exception is
> thrown or because of the extra checking involved when you wrap
> exceptions around code?[/color]

This is implementation-specific. According to Stroustrup (TC++PL, p. 381),
"In principle, exception handling can be implemented so that there is no
run-time overhead when no exception is thrown." However, it is known, for
example, that VC++ exception handling does have a run-time cost even when no
exception is thrown. This cost is only small so can be ignored for most
purposes.


--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

John Harrison
Guest
 
Posts: n/a
#3: Jul 22 '05

re: how are exception expensive?



"John Carson" <donaldquixote@datafast.net.au> wrote in message
news:40909b58$1@usenet.per.paradox.net.au...[color=blue]
> "Monster" <monster@this.monster@that> wrote in message
> news:hpOdnZWg4IsHFw3dRVn-uQ@giganews.com[color=green]
> > Are they expensive because of what happens when an exception is
> > thrown or because of the extra checking involved when you wrap
> > exceptions around code?[/color]
>
> This is implementation-specific. According to Stroustrup (TC++PL, p. 381),
> "In principle, exception handling can be implemented so that there is no
> run-time overhead when no exception is thrown." However, it is known, for
> example, that VC++ exception handling does have a run-time cost even when[/color]
no[color=blue]
> exception is thrown. This cost is only small so can be ignored for most
> purposes.
>[/color]

Any cost may also be less than the traditional alternative of checking the
return value of every function call. That obviously has a run time cost, but
even more importantly leads to great difficulties in code maintenance. I've
seen many, many examples of code which is trying to catch rarely occurring
errors in a deeply nested series of function calls, but where the code
doesn't work correctly in the face of errors, inevitably because some return
values aren't checked.

john


jeffc
Guest
 
Posts: n/a
#4: Jul 22 '05

re: how are exception expensive?



"John Harrison" <john_andronicus@hotmail.com> wrote in message
news:c6q6i4$f1fjb$1@ID-196037.news.uni-berlin.de...[color=blue]
>
> Any cost may also be less than the traditional alternative of checking the
> return value of every function call.[/color]

Yeah, that's a good point.
[color=blue]
> That obviously has a run time cost, but
> even more importantly leads to great difficulties in code maintenance.[/color]

Well now you're changing the subject :-)


Closed Thread