This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Exception Specifications


On Dec 6, 2006, at 9:21 AM, John Love-Jensen wrote:

Hi Perry,

I only use "no throw" specification, i.e., throw(), on functions that
absolutely guarantee that they do not throw. And I use it sparingly, only
on my functions that really shouldn't throw, ever, such as swap functions,
and I know (a priori) that those functions will never throw.


NOTE: I have been stung by writing a "no throw" function, annotated with
throw(), and even commented in the contract comments, yet someone later put
in some additional "helpful" tracing/debugging facilities that did throw in
some situations... no joy in Mudville. Caveat emptor.


I do not put itemized throw specifications on functions.

I highly recommend C++ Coding Standards by Sutter and Alexandrescu, in
particular the section on Error Handling and Exceptions.

Moreso, I highly recommend all of Sutter's books on C++.

Thanks. I've been surfing the past few minutes and bumped into two of Sutter's books: Exceptional C++ and More Exceptional C++. They look interesting.


The one place that I'm a little disappointed is that you can do this:

int foo()
{
    throw 92;
}

int dog() nothrow()
{
    foo();
}

Of course, the code produced catches that at run time but I'm looking for something somehow to tag my functions so that "mistakes" like this are caught at compile time. (Similar to what happened to you. I'm looking for a way to catch that at compile time.) I wonder if g+ + has a compile time flag to catch that.

Perry Smith ( pedz@easesoftware.com )
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]