-
November 6th, 2003, 01:15 PM
#1
what is _THROW0 macro ?
Hi Gurus,
by browsing STL files I saw this _THROW0 strange macro a lot of time at end of methods declaration.
According to XSTDDEF file:
Code:
#define _THROW0() throw ()
For instance declaration of release method of auto_ptr is:
Code:
_Ty *release() const _THROW0()
What does it mean ? Is it like Java to specify the method can send exceptions. Anyway it does not seem to be checked by the compiler to verify callers are catching thrown exceptions.
Any information about this is welcome.
Thanks
-
November 6th, 2003, 01:25 PM
#2
Is it like Java to specify the method can send exceptions. Anyway it does not seem to be checked by the compiler to verify callers are catching thrown exceptions.
Bing! We have a winner!
MSDN, "Exception Specifications"
The following table summarizes Visual C++'s implementation of exception specifications:
Code:
Exception specification Meaning
throw() The function does not throw an exception.
throw(...) The function can throw an exception.
throw(type) The function can throw an exception of type type. However, in Visual C++ .NET, this is equivalent to throw(...).
Thought for the day/week/month/year:
Windows System Error 4006:
Replication with a nonconfigured partner is not allowed.
-
November 6th, 2003, 01:26 PM
#3
Apologize for quoting MSDN in the "C++ (Non Visual C++ Issues)" forum...
Thought for the day/week/month/year:
Windows System Error 4006:
Replication with a nonconfigured partner is not allowed.
-
November 6th, 2003, 01:27 PM
#4
Just be careful when using this in your own methods. In fact, don't unless you are very very certain that your method can't throw. The compiler has no way to determine if a method satisfies this requirement, and if it does happen to throw, the program will not pass go, it will not collect $200. It will call terminate().
Jeff
-
November 7th, 2003, 04:11 AM
#5
All right,
here is what I tried:
Code:
class CDummy
{
public:
CDummy() {};
virtual ~CDummy() {};
virtual void doSomething() throw(exception) {
throw new exception();
}
};
void doSomethingElse() {
CDummy oneDummy;
oneDummy.doSomething();
}
And the compiler does not complain about method doSomethingElse does not catch exception. Why ?
-
November 7th, 2003, 04:16 AM
#6
By the way, I did not succeed to compile a throw(...). Any idea about this ?
What is the goal of these throw methods declaration if never checked by compiler ? Is it a kind of "future use" functionalities, is it just to decorate the code ?
-
November 7th, 2003, 07:21 AM
#7
What compiler are you using? The doc I posted was for VC++ 7.1.
Again, MSDN (Oct 2003):
"C++ Language Reference", "Nonstandard Behavior":
The following topics are some of the known places where the Visual C++ implementation of C++ does not agree with the C++ standard. The section numbers refer to section numbers in the C++ standard.
...
15.4 Function Exception Specifiers
Function exception specifiers other than throw() are parsed but not used. For example:
void f() throw(int); // parsed but not used
void g() throw(); // parsed and used
For an excellent discussion on this topic, may I recommend the following MSDN article (I'm a MSDN addict):
"Handling Exceptions, Part 11" by Robert Schmidt
Actually, the entire "Handling Exceptions" series is worth several reads...
Thought for the day/week/month/year:
Windows System Error 4006:
Replication with a nonconfigured partner is not allowed.
-
November 7th, 2003, 07:34 AM
#8
Thanks vicodin451 for your answers.
What compiler are you using? The doc I posted was for VC++ 7.1.
I am using a 6.0
For an excellent discussion on this topic, may I recommend the following MSDN article (I'm a MSDN addict):
Thanks I will read this.
-
November 7th, 2003, 11:20 AM
#9
The caller is not required to catch what a method throws. There is no such rule in C++.
I'd strongly suggest not doing this. There is very little benefit, and very serious consequences if your method throws something other than what you specify.
Also there's no reason to have throw(...). Every method that does not specify anything is assumed to be throw(...), meaning it may throw anything.
You really need to read Herb Sutter's Exceptional C++ before venturing further. You need to understand this stuff before you use it or it will bite you.
Jeff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|