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