Exceptions

R

roberts.noah

Scott Myers discusses the 'costs' of exceptions even when not being
used vs. when you have a try/catch block vs. when you have to throw an
exception. He leads you to believe that these costs are quite
significant with a 10% increase in code size and slow down just by
having the capability to use exceptions. He admits to not really
having any concrete data for this but he still asserts pretty strongly
that exceptions have a rather high cost.

But this book (More Effective C++) was written several years ago. Is
there a better understanding now? Do exceptions really cost that much
when they are not fired? I did some google searching but haven't come
up with much.
 
B

BigBrian

Scott Myers discusses the 'costs' of exceptions even when not being
used vs. when you have a try/catch block vs. when you have to throw an
exception. He leads you to believe that these costs are quite
significant with a 10% increase in code size and slow down just by
having the capability to use exceptions. He admits to not really
having any concrete data for this but he still asserts pretty strongly
that exceptions have a rather high cost.

But this book (More Effective C++) was written several years ago. Is
there a better understanding now? Do exceptions really cost that much
when they are not fired?


Write some test code and try it out with your complier and report your
results.
 
P

peter koch

Scott Myers discusses the 'costs' of exceptions even when not being
used vs. when you have a try/catch block vs. when you have to throw an
exception. He leads you to believe that these costs are quite
significant with a 10% increase in code size and slow down just by
having the capability to use exceptions. He admits to not really
having any concrete data for this but he still asserts pretty strongly
that exceptions have a rather high cost.

But this book (More Effective C++) was written several years ago. Is
there a better understanding now? Do exceptions really cost that much
when they are not fired? I did some google searching but haven't come
up with much.

Exceptions do have a cost, yes. So of course does any mechanism with
which you check for runtime errors.
The Technical report of C++ performance (google for it!) has a good
discussion of overhead of exceptions. Go read it.

/Peter
 
T

Thomas Tutone

Scott Myers discusses the 'costs' of exceptions even when not being
used vs. when you have a try/catch block vs. when you have to throw an
exception. He leads you to believe that these costs are quite
significant with a 10% increase in code size and slow down just by
having the capability to use exceptions. He admits to not really
having any concrete data for this but he still asserts pretty strongly
that exceptions have a rather high cost.

But this book (More Effective C++) was written several years ago. Is
there a better understanding now? Do exceptions really cost that much
when they are not fired? I did some google searching but haven't come
up with much.

It's a quality of implementation issue. Do some searching in
comp.lang.c++.moderated, and you should find quite a bit on it.
Originally, having try-catch blocks often led to an increase in code
size and a decrease in execution speed, even if exceptions were not
thrown. On many platforms today, however, the situation has changed.
Although using try-catch blocks still often leads to a slight increase
in code size, on may platforms, there is no significant decrease in
execution speed unless an exception is actually thrown.

As another poster said, the only way to know for sure is to test it on
your platform.

Best regards,

Tom
 

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,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top