What does it cost to try?

  • Thread starter Steven T. Hatton
  • Start date
S

Steven T. Hatton

What is the runtime cost of wrapping a function call in a try/catch? I
assume it's something like an if/else when it goes on the stack. I believe
that means an additional compare and an additional memory location to
branch to. Would this be significant enough to make a difference between
say putting the try{}catch{} inside the body of a loop as opposed to
wrapping the loop in the try/catch?
 
D

David Hilsee

Steven T. Hatton said:
What is the runtime cost of wrapping a function call in a try/catch? I
assume it's something like an if/else when it goes on the stack. I believe
that means an additional compare and an additional memory location to
branch to. Would this be significant enough to make a difference between
say putting the try{}catch{} inside the body of a loop as opposed to
wrapping the loop in the try/catch?

This is obviously implementation-dependent. The g++ compiler even offers
flags to control the "cost" of using exceptions
(http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Exception-Handling-Control.html)
.. You might get better answers in a newsgroup that discusses your
implementation.
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top