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

Stefan Seefeld <[email protected]>
Newsgroups gmane.comp.video.fresco.devel
Message-ID <[email protected]>
Neil Pilgrim wrote:
> 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? ;)

you shouldn't. Users shouldn't throw anything but user exceptions.

> - generally don't bother with exception specifications

I think exception specs are good to document the intention (similar
to 'const'), but they may be hard to fulfill. If you can really
guarantee that only std::runtime_error will be thrown, you may as well
embed that statement into the API.

> - except possibly throw() on non-inline non-virtual non-template
> functions

huh ?


>>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...

exactly. You can only declare user exceptions anyways, which are only
a tiny fraction of all thrown exceptions, see our own code for an illustration.

Stefan
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.