By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,702 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

What does it cost to try?

P: n/a
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?
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:2v********************@speakeasy.net...
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_u...g-Control.html)
.. You might get better answers in a newsgroup that discusses your
implementation.

--
David Hilsee
Jul 22 '05 #2

P: n/a
"David Hilsee" <da*************@yahoo.com> wrote in message
news:Cs********************@comcast.com...
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:2v********************@speakeasy.net...
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_u...g-Control.html) . You might get better answers in a newsgroup that discusses your
implementation.


Sorry, I linked to an Ada compiler, but the message is still the same.

--
David Hilsee
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.