By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,925 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,925 IT Pros & Developers. It's quick & easy.

Is throw specification necessary?

P: n/a
wij
Hi:
In recent pondering, I am begining suspecting the usefulness of
throw specification in the language(I know this opinion have long
existed), even for delete!. The primary reason is that
reimplementing such members or functions cannot throw any types
other than specified (what would be the justifiable reason?
Besides, stack unwinding may be initiated by NPTL implemented
cancellation with unspecified throw type and compiler may enable
arithmetic exception...

From another aspect, is there any practically useful case that
throw spc. is really better than no spc. but documented?
(except high level apps infrequently called, which may want such
runtime check)

Regards

Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
I believe a few of your questions are answered in :

http://distributed-software.blogspot...rrectness.html

I would be interested in knowing how the article works for you. In case
you choose to read it, feel free to use my email.

Regards,
Dr. Z.
Chief Scientist
zo****@ZHMicro.com
http://www.zhmicro.com
http://distributed-software.blogspot.com

Jul 23 '05 #2

P: n/a


Zorro wrote:
I believe a few of your questions are answered in :

http://distributed-software.blogspot...rrectness.html

Excellent Article, I also didn't know so much.

Jul 23 '05 #3

P: n/a
I am glad you found the article useful.

Thanks.
Z.

Jul 23 '05 #4

P: n/a
I am glad you found the article useful.

Thanks,
Z.

Jul 23 '05 #5

P: n/a
wij
Zorro:

From the link you provide,
http://distributed-software.bl ogspot.com/2005/07/exception-m
echanism-...
A paragraph suggesting the union of the throw specification
looked inspiring. But the "First EMC Rule. The set of
exceptions that a function could throw must be a subset of
those specified at its prototype." seemd contradictory...
But, sorry, I am mentally confined to the question: Is there
any practically useful case that throw spc. is really better
than no spc. but documented?

Jul 23 '05 #6

P: n/a
wi*@seed.net.tw wrote:
Hi:
In recent pondering, I am begining suspecting the usefulness of
throw specification in the language(I know this opinion have long
existed), even for delete!. The primary reason is that
reimplementing such members or functions cannot throw any types
other than specified (what would be the justifiable reason?
Besides, stack unwinding may be initiated by NPTL implemented
cancellation with unspecified throw type and compiler may enable
arithmetic exception...

From another aspect, is there any practically useful case that
throw spc. is really better than no spc. but documented?
(except high level apps infrequently called, which may want such
runtime check)

Regards

No, it's completely useless.

As are types, const etc. Just use void* for everything.

OK, perhaps types are usefull. Hmm, and const.

Come to think of it, tightly specifying everything at compile time and getting the compiler to spot errors in the form of misuse of those specifications IS pretty useful!

Ben
--
I'm not just a number. To many, I'm known as a String...
Jul 23 '05 #7

P: n/a
I am too old for remembering all the articles I have read over the
years. I am sure someone will be kind enough to tell you about a few
that discuss the usefulness of the throw spec.

On the contradictory part. Basically, the compiler is responsible to
ensure that in the definition (body) of the method you do not throw an
exception that was not specified at the prototype of that function.
This is because at the point of calling this method, the compiler may
only have seen the prototype (the specification of the method).

I hope this helps. My email is "zorabi" at "zhmicro.com". It seems that
my email is not showing well if I typed it as usual.

Thanks for reading the article.
Regards,
Z.

Jul 23 '05 #8

P: n/a


Ben Pope wrote:
wi*@seed.net.tw wrote:
Hi:
In recent pondering, I am begining suspecting the usefulness of
throw specification in the language(I know this opinion have long
existed), even for delete!. The primary reason is that
reimplementing such members or functions cannot throw any types
other than specified (what would be the justifiable reason?
Besides, stack unwinding may be initiated by NPTL implemented
cancellation with unspecified throw type and compiler may enable
arithmetic exception...

From another aspect, is there any practically useful case that
throw spc. is really better than no spc. but documented?
(except high level apps infrequently called, which may want such
runtime check)

Regards
No, it's completely useless.

As are types, const etc. Just use void* for everything.

OK, perhaps types are usefull. Hmm, and const.

Come to think of it, tightly specifying everything at compile time and getting the compiler to spot errors in the form of misuse of those specifications IS pretty useful!


The problem is that the compiler does not detect anything. Rather, the
compiler enforces the throw-specification. As an example:

int f() throw()
{
throw std::exception("what??");
return 0;
}

This function is perfectly legal.

/Peter

Ben
--
I'm not just a number. To many, I'm known as a String...


Jul 23 '05 #9

P: n/a
wij
Ben Pope wrote:
Come to think of it, tightly specifying everything at compile time and
getting the compiler to spot errors in the form of misuse of those
specifications IS pretty useful!
That's one of C++'s ideal, sometimes gone too far. But I am digging
for the useful part.
No, it's completely useless.
Great! (But much harder to prove)
I'm not just a number. To many, I'm known as a String...


I'm but a mirror, all you see is yourself.

Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.