Re: [Fresco-devel] Coding standard: throw specifications

Neil Pilgrim <[email protected]>
Newsgroups gmane.comp.video.fresco.devel
Message-ID <[email protected]>
Nathaniel Smith wrote:
> On Sun, Jan 05, 2003 at 10:12:42AM +0000, Neil Pilgrim wrote:

> Throw specifications mean very different things in IDL and C++
> (reasonably, considering that the exception handling systems are
> totally different too...).  In IDL, throw specs are a way of
> _enabling_ exceptions -- you can only throw exceptions that you have
> throw specs for.  In C++, throw specs are a way of _disabling_
> exceptions -- you guarantee that you'll never throw any exception
> besides those listed (enforced by crashes, IIRC).  The two systems are
> quite orthogonal.

I completely agree...almost...but you might say that throw specs are a
way of enabling *user* exceptions - I believe that with corba you can
throw some SystemExceptions, eg. OBJECT_NOT_EXIST? ;)

> There's, on average, a bias against using them in C++, because
> normally you should let exceptions propagate to the best place to deal
> with them; throw declarations used incautiously can interfere with
> this and make for worse error handling.  That doesn't mean that you
> shouldn't use them, though, just be careful and use them where it's a
> good idea :-).

Well, I was just going from what I've read on various newsgroups and
websites, eg.
http://www.boost.org/more/lib_guide.htm#Exception-specification
http://www.gotw.ca/gotw/082.htm
http://www.gotw.ca/publications/mill22.htm

IIRC a summary would be:
- generally don't bother with exception specifications
- except possibly throw() on non-inline non-virtual non-template
functions

Of course, if the call is away from the main line of code, there should
be no efficiency overhead, but I still see no benefit from using them.
If a function is some member function which does very little, nothing
external, and all throw clauses are visible inside the function
definition then I can see that it should have no drawbacks...but surely
it is better to not use them everywhere, rather than saying 'use them
only if (A && B && C && D && ...)' ie. just in special cases. There are
enough special-cases like this in C++ as it is, without this...

AFAICT good comment is just as useful!

> In IDL, of course, it's a different beast; use them whenever you want
> to let a method throw an exception (and throwing an exception is
> generally considered to be a good way to signal an error, no?).

I agree with this entirely...except that the caller may exit wrongly all
over the place if the exception is not caught. Of course that may be a
'good thing', ie. you should always include error-handling, *especially*
with corba, where exceptions can come from any call...

> > b) Should the decision of this be added to the coding standard? Latest
> > version is at http://www2.fresco.org/coding-style.html (*not* www, only
> > www2).
> 
> I don't think it's a style issue so much as an API design issue, and
> as such seems beyond the scope of the coding guidelines.

Well I was edging towards this, but then we currently include
- const correctness
- new casts (incidentally, with the wrong indentation level)
- macro avoidance

These are not strictly 'style' issues either?

-- 
Neil
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.