Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: OT: How does one get rid of a non-C++ exception?

Author: KarinsDad

Date: 08:10:29 06/02/00

Go up one level in this thread


On June 02, 2000 at 09:34:22, Daniel Clausen wrote:

>Hi
>
>Note: This is very off-topic on CCC so if you're looking for something chess-
>      related, press your back-button. :)


I've always disagreed with this viewpoint. If I have a bug in my computer chess
program, then resolving that bug is computer chess related. Regardless of
whether it is a compiler problem, an algorithm problem, or any other type of
programming problem. Otherwise, this place would be called the Chess Club (for
playing computer chess, not for programming it), IMO.


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


How does one do a catch(...) with CATCH? How does one get rid of the unknown
exception object?


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


Yes, of course. I just call them that since most people who use MSVC understand
what you mean when you say that. But, you are literally correct.


>
>- 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 :)


I realize this. I knew all along what my problem was. However, I do not know the
solution (yet). However, since I do not know WHAT exception object I am supposed
to be catching, how do I write code to catch it? For example, catch(char* c)
will only catch pointers to characters, not to anything else.


>  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


Well, the throw information you gave is not really relevent to the problem at
hand. If you look at my original code, I do not want to throw anything. I want
to delete whatever exception object was thrown to me. I then want to loop back
and get back into my try block.

Does anyone have a code snippet that will do this for me?

KarinsDad :)



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.