473,320 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how are exception expensive?

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?
Jul 22 '05 #1
3 2044
"Monster" <mo*****@this.monster@that> wrote in message
news:hp********************@giganews.com
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.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #2

"John Carson" <do***********@datafast.net.au> wrote in message
news:40********@usenet.per.paradox.net.au...
"Monster" <mo*****@this.monster@that> wrote in message
news:hp********************@giganews.com
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.


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
Jul 22 '05 #3

"John Harrison" <jo*************@hotmail.com> wrote in message
news:c6************@ID-196037.news.uni-berlin.de...

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 :-)
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Larry Foulkrod | last post by:
Should I throw an exception in the following scenario? I have a user class. The constructor takes one argument, the sessionid of the user. This sessionid corresponds to an entry in a database. ...
28
by: Frank Puck | last post by:
Meanwhile there are at least 8 years that compilers exist, which provide a working implementation of C++ Exception Handling. Has anything changed meanwhile? From my point of view nothing has...
3
by: Gonçalo Rodrigues | last post by:
Hi all, I've got two somewhat general questions related to exception handling in C++. My usual programming language is the lovely and flexible Python, but for various reasons, including the need...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
5
by: Bevo | last post by:
In my enterprise application I'd like my DataAccess layer to be responsible for handling all database error situations and to basically throw custom exceptions according to whether db connection is...
9
by: Paulustrious | last post by:
Is it possible to override the behaviour of a dictionary if an object is not found? string ss=null; Dictionary<string, string> dict = new Dictionary<string, string>(); // method 1 try {...
43
by: Shehab Kamal | last post by:
Which approach is better: 1) Use a method that returns true/false (the method will log the exception that lead to false using log4net for example) OR 2) Use a method that returns void and throws...
17
by: cashdeskmac | last post by:
Nice and simple one for you all... Is there a time to use Catch(Exception) rather than creating an instance of the Exception, as in Catch(Exception ex)?
24
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.