Author: Daniel Clausen
Date: 06:34:22 06/02/00
Go up one level in this thread
Hi
Note: This is very off-topic on CCC so if you're looking for something chess-
related, press your back-button. :)
On June 01, 2000 at 13:02:15, KarinsDad wrote:
>>Function1 calls some Win32 API calls and I think that one of them throws a
>>non-C++ exception (i.e. it does not get caught in the catch(CException* e) code
>>above). Since this is in a loop, the exception does not get deleted (like a C++
>>exception would get deleted in the code above), so once Function1 throws a
>>non-C++ exception, this code (catch(...)) reports it, loops back, immediately
>>finds an exception within the Try block, and reports the exception again
>>(effectively infinitely looping).
And on June 01, 2000 at 21:20:36, Vincent Vega wrote:
>Sure, use TRY and CATCH (note capitals). Microsoft wanted to add exceptions
>before their C++ compiler supported them and that's what they added to MFC.
I've no idea what the macros mentioned above wrap exactly, but let me add
this.
- There's no such thing as a C++ or non-C++ exception. (in C++ that is ;)
Std C++ doesn't provide a generic superclass for exceptions. [In fact
Std C++ doesn't provide *any* superclass.]
I assume that "CException" is M$'s generic exception class and all
their exceptions derive from it.
- Since there is no generic superclass for exceptions in Std-C++, a
function can throw anything it wants, can be ints, pointers to arrays
containing functions pointers to functions returning double**.
[Hope you get the idea :)]
A friend of mine wrote this code fragment some weeks ago:
try
{
// Do something.
}
catch(...)
{
MyClass anObject(); // (1)
throw anObject; // (2)
}
The compiler happily compiled this, but the linker was unhappy and
complained about an unresolved symbol 'anObject'.
The problem is that the compiler treated line (1) as a forward declaration
of a function with the name 'anObject' taking no arguments and returning
something of type 'MyClass'. In the line (2) you throw a function pointer.
Well...
Note: The solution to this is to not use the brackets () when you want to
call the default constructor.
- Most decent C++-libraries I know (not many I agree) throw exception objs
as values. In this case you can catch them as a reference and don't have
a problem with freeing. That also solves the catch(...) because you can't
free anything there. (that was your problem :)
You could also catch by value but then your exception object will be copied
for nothing.
- You can use the throws keyword in functions:
void calculateSomething(void) throws CException;
This doesn't buy you a lot though, because it doesn't hinder the function
'calculateSomething' to throw something which isn't CException. (or
derived from) And what's worse: it converts it to 'unknownExp' or
something similar.
Basically the throws keyword is for almost nothing since there's no base-
class for exceptions in C++. (It works good in Java though.)
I hope I didn't make too many mistakes (please correct me otherwise!) and
didn't bore you too much. (Hey, I warned you in the beginning!)
Regards,
-sargon
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.