how are exception expensive?

M

Monster

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

John Carson

Monster said:
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?

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

John Harrison

John Carson said:
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.

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
 
J

jeffc

John Harrison said:
Any cost may also be less than the traditional alternative of checking the
return value of every function call.

Yeah, that's a good point.
That obviously has a run time cost, but
even more importantly leads to great difficulties in code maintenance.

Well now you're changing the subject :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top