Computer Chess Club Archives


Search

Terms

Messages

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

Author: Vincent Vega

Date: 20:51:56 06/02/00

Go up one level in this thread


On June 01, 2000 at 13:02:15, KarinsDad wrote:

>In my code, I have something similar to the following:
>
>while (bIsRunning)
>{
>  try
>  {
>    Function1();
>  }
>  catch(CException* e)
>  {
>    ReportError(e);
>    e->Delete();
>  }
>  catch(...)
>  {
>    ReportError();
>  }
>}
>
>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).
>
>However, this appears to only happen with certain exceptions, but not all
>exceptions (for example, if I just try to replace Function1 with a throw myself,
>I cannot reproduce this behavior).
>
>Does anyone have an idea on how to get rid of an exception caught within the
>catch(...)?
>
>Thanks,
>
>KarinsDad :)

This code behaves exactly as it should, but the ReportError() function can only
be called in the first catch clause: e->ReportError();, not ReportError(e);.
You "get rid" of the exception by catching it.  Then you loop again and if the
same exception occurs again, it is thrown and caught again, and so on.  I don't
understand what you mean by "immediately finds an exception within the Try
block."  The program will only throw another exception because it encounters a
throw statement again, not because the previous exception wasn't "deleted" and
the try {} catch() is entered.



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.