473,848 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arguments *Against* Exception Use

Hi, all,

I just got out of a meeting with a team of software developers that I
recently joined as they are staffing to create a medium-sized project
(potentially all of which will be written in C++). From my experience and
readings, I've come to this group indoctrinated to use exceptions for error
handling. The experience in this group that leads them to believe that
exceptions should only be used where severe runtime errors require program
termination is mainly based on the notion that the performance impact of
exceptions is prohibitive.

Besides the Meyers books and my trusty copy of "C++ FAQs", I'm going on my
intuition based on years of experience. Am I over-indoctrinated in the use
of exceptions? Are there some warnings that I'm not heeding? Can
exceptions impact performance to the degree that my coworkers claim? I'd
like to hear some anti-exception thoughts, if they exist.

Thanks!
Scott

--
Remove .nospam from my e-mail address to mail me.

http://www.e-scott.net
Jul 22 '05 #1
28 2199
* Scott Brady Drummonds:
Hi, all,

I just got out of a meeting with a team of software developers that I
recently joined as they are staffing to create a medium-sized project
(potentially all of which will be written in C++). From my experience and
readings, I've come to this group indoctrinated to use exceptions for error
handling. The experience in this group that leads them to believe that
exceptions should only be used where severe runtime errors require program
termination is mainly based on the notion that the performance impact of
exceptions is prohibitive.

Besides the Meyers books and my trusty copy of "C++ FAQs", I'm going on my
intuition based on years of experience. Am I over-indoctrinated in the use
of exceptions? Are there some warnings that I'm not heeding? Can
exceptions impact performance to the degree that my coworkers claim? I'd
like to hear some anti-exception thoughts, if they exist.


Context?

If coding for a micro-controller or, say, an OS kernel: yes, C++ exceptions
are probably UnGood.

Otherwise: no, C++ exceptions are Good.

But regardless of context, if the question is really on the table, then one
reasonable way to proceed could be to measure typical code. Things to
measure: time needed to complete correctly functioning code, time needed to do
some modification of the code, execution time in ordinary usage.

I bet those software developers think raw pointers and Hungarian notation (not
to mention a "repository " to copy code snippets from!) are nice ideas, too...

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
"Scott Brady Drummonds" <sc************ **********@inte l.com> wrote in
message news:cm******** **@news01.intel .com...
I'd like to hear some anti-exception thoughts, if they exist.


You may want to read Herb Sutter's article named When and How to Use
Exceptions, in the August 2004 issue of the C/C++ Users Journal.

If you decide to use exceptions in the project, the section dedicated to
exceptions in the book Exceptional C++ by Herb Sutter will be
exceptionally useful :) There are sequels to this book, which should be
helpful too, but I haven't read them yet:

http://www.gotw.ca/publications/index.htm

Ali

Jul 22 '05 #3
"Scott Brady Drummonds" <sc************ **********@inte l.com> wrote in
message news:cm******** **@news01.intel .com...
Hi, all,

I just got out of a meeting with a team of software developers that I
recently joined as they are staffing to create a medium-sized project
(potentially all of which will be written in C++). From my experience and
readings, I've come to this group indoctrinated to use exceptions for
error
handling. The experience in this group that leads them to believe that
exceptions should only be used where severe runtime errors require program
termination is mainly based on the notion that the performance impact of
exceptions is prohibitive.

Besides the Meyers books and my trusty copy of "C++ FAQs", I'm going on my
intuition based on years of experience. Am I over-indoctrinated in the
use
of exceptions? Are there some warnings that I'm not heeding? Can
exceptions impact performance to the degree that my coworkers claim? I'd
like to hear some anti-exception thoughts, if they exist.

Thanks!
Scott

--
Remove .nospam from my e-mail address to mail me.

http://www.e-scott.net


I never could figure out how use of exceptions could cause such big run time
errors. If you use them properly as error handlers rather than control
structures they won't be invoked often enough to run up much execution time.
And if you avoid exception specifications (which are basically useless
anyway) they don't have much overhead at all.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #4
Scott Brady Drummonds wrote:
I just got out of a meeting with a team of software developers
that I recently joined as they are staffing to create
a medium-sized project (potentially all of which will be written in C++).
From my experience and readings,
I've come to this group indoctrinated to use exceptions for error handling.
The experience in this group that leads them to believe that
exceptions should only be used
where severe runtime errors require program termination
is mainly based on the notion that
the performance impact of exceptions is prohibitive. Besides the Meyers books and my trusty copy of "C++ FAQs",
I'm going on my intuition based on years of experience.
Am I over-indoctrinated in the use of exceptions?
Are there some warnings that I'm not heeding?
Can exceptions impact performance to the degree that my coworkers claim?
I'd like to hear some anti-exception thoughts, if they exist.


Your question is very vague.

No, the exception handling mechanism should *not* be used
for normal flow control. It should only be used
for expected but unpredictable and unpreventable events
that are rare *exceptions* to the normal result.
The exception handling mechanism was designed to be implemented
so that *no* additional overhead is required
if an exception is not thrown.
If an exception is thrown, a great deal of extra computation
may be required to handle it.

The exception handling mechanism should *not* be used
to detect and locate programming errors (bugs).
Programming errors are *not* exceptions
because they are not expected
and are both predictable and preventable once detected.

Exceptions are not always errors.
They may be events, such as running out of memory,
over which your program has no control.
Listen to your coworkers.
From what you have told us,
it appears that they know what they are talking about.
Jul 22 '05 #5
Cy Edmunds wrote:
Scott Brady Drummonds wrote:
[snip]
I never could figure out how
use of exceptions could cause such big run time errors.
If you use them properly as error handlers rather than control structures
Although Scott doesn't say this,
I suspect that this is what his coworkers are complaining about.
they won't be invoked often enough to run up much execution time.
And if you avoid exception specifications
(which are basically useless anyway)
they don't have much overhead at all.


The assumption is that exceptions are rarely thrown.
Jul 22 '05 #6
> they won't be invoked often enough to run up much execution time
What is I hear that to setup try block does cost CPU time?
Which actually makes sense to me, since the program has to setup
unwind information.

I would imagine your program have more or less localized exception
handling, as opposed to :

main()
{
try{
doeverythingels e();
}catch(...){
printf("caught exception");
}

Anybody wants to add more details on this issue?

Actually the biggest issue with exceptions for me is that you cannot
through them across library boundary, especially if the libs are done
with different compilers. (although its not exactly exceptions fault, the
problem still stands)

Igor

"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:cm******** **@nntp1.jpl.na sa.gov...
Cy Edmunds wrote:
Scott Brady Drummonds wrote:


[snip]
I never could figure out how
use of exceptions could cause such big run time errors.
If you use them properly as error handlers

rather than control structures


Although Scott doesn't say this,
I suspect that this is what his coworkers are complaining about.
they won't be invoked often enough to run up much execution time.
And if you avoid exception specifications
(which are basically useless anyway)
they don't have much overhead at all.


The assumption is that exceptions are rarely thrown.

Jul 22 '05 #7
> And if you avoid exception specifications (which are basically useless
anyway) they don't have much overhead at all.


I disagree.
- An interface designer can specify the expected error values so that
the developer or programmer must adhere to such restrictions in the
implementation.

- If the an exception specification is omitted, the compiler (that
does not perform inter-procedural analysis) must assume that every
possible exception can be thrown and must be prepared to generate code
for the handling of stack unwinding and related stuff. This detail can
be optimized if you add "throw()" to your functions and methods
because no exceptions will be thrown.

Regards,
Markus
Jul 22 '05 #8
Markus Elfring wrote:
And if you avoid exception specifications (which are
basically useless anyway) they don't have much overhead at all.


I disagree.


I agree (with your disagreement).

I recently benchmarked some highly optimised low-level number-crunching
code with and without exception handling [floating point exception
trapping was not enabled in either case]. Even when no exceptions were
being thrown there was a performance hit of about 20% with exception
handling enabled [with or without explicit exception specification -
this didn't seem to make much difference].

--
Lionel B

Jul 22 '05 #9
> Besides the Meyers books and my trusty copy of "C++ FAQs", I'm going on my
intuition based on years of experience. Am I over-indoctrinated in the use
of exceptions? Are there some warnings that I'm not heeding? Can
exceptions impact performance to the degree that my coworkers claim? I'd
like to hear some anti-exception thoughts, if they exist.


Would you like to develop for evironments with very limited resources?
How do you think about this article by P. J. Plauger?

Embedded C++: An Overview
Is EC++ the diet pill that will shrink C++ down to size for embedded applications?
http://www.ghs.com/download/ec++.pdf
Jul 22 '05 #10

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

Similar topics

66
5050
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
2
8240
by: Steven D'Aprano | last post by:
I'm trying to keep an open mind, but I am perplexed about something in Python that strikes me as a poor design. py> def func(a,b): py> print a,b py> func(1) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: func() takes exactly 2 arguments (1 given)
15
4225
by: Pohihihi | last post by:
This might sound little stupid to many but I was thinking that when we can use object why we really need event args to pass in any functions e.g. bool MyFunction(object sender, System.EventArgs e){} my question is targetted more on the customized event arguments that we create while programming. Is it just to make it more readable or maybe to make things in collective and hierarchy?
2
2983
by: jn | last post by:
Hi, I'm passing around 30 arguments to a stored procedure, and I got the following error (see below). It works fine if I narrow down to around 25 args. Is there any workaround to bypass this exception, I need to pass 30 of them to my stored procedure. Thanks. I'm using Framework 1.0. -----------------------
2
4625
by: Mary Pegg | last post by:
No point re-inventing the wheel, so thought I'd see if anybody's got some good example code kicking around. (Please excuse trivial syntactical errors, it's all coming off the top of my head). Say I have a function thus: function munge($a) { return ($a * 2);
18
12088
by: luco | last post by:
Hi! I'm having a problem with attachEvent function. I'd like to add attachEvent dynamically to some objects so that each could execute event function with different parameter value. The question is: how to pass the parameter to event function? The following code obviously doesn't work, how should i modify it to get it to work?
36
2742
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called on it's own. However when I call the child object I get an error " has no properties (in firefox)." I simple test:
12
3491
by: -Lost | last post by:
What in the world is functionName.name good for? That is: function functionName() { return functionName.name; } I mean, I already had to write out the function's name so it seems that it is not very useful or efficient. To me, this.name seems most appropriate, but of course that does not work within the context of a function unless defined as a class, which of course then the name property does not apply to the calling function.
9
1514
by: parag_paul | last post by:
hi All, I am working on a different language called System Verilog which is trying to support classes as a construct, Now our compiler allows something like the following class C { void print(); }
0
9893
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10722
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.