Catching Exceptions with catch(...): How do I get exception info? 
Author Message
 Catching Exceptions with catch(...): How do I get exception info?

I have an exception that is being thrown in my program.  I have no idea what
type of exception it is.   I can catch it with catch(...).  Is there any why
to get an error message from this exception or to determine what type it is?

FYI This is being thrown when making a can to the Run method in the MS
Script Control if that is any help.



Wed, 02 Aug 2000 03:00:00 GMT  
 Catching Exceptions with catch(...): How do I get exception info?

Assuming your using MFC and you are catching a CException object you can use
the GetErrorMessage member to get a string representation of the error

--
Its a big enough umbrella,
  But its always me that ends up getting wet....
 ---------------------------------------------------------------------------
---
| Author for Pinnacle Publishing "Visual C++ Developer"
http://www.pinpub.com/ |
| http://lucifer.lotus.com/jim/main.htm
|
 ---------------------------------------------------------------------------
---



Wed, 02 Aug 2000 03:00:00 GMT  
 Catching Exceptions with catch(...): How do I get exception info?

Nope already tried that.  I dosn't seem to work for me, unless I'm doing
something wrong.  I tried a

catch(CException *e)
{
    .......
    e->GetMessage(

Quote:
}

and I tried

catch(...)
{

    CException e;
   e.GetMessage

Quote:
}

In the first example, It dosen't even catch the exception.  In the second
example (I'm sure it's wrong) it dosen't show an error message.

Please help.

Quote:

>Assuming your using MFC and you are catching a CException object you can
use
>the GetErrorMessage member to get a string representation of the error

>--
>Its a big enough umbrella,
>  But its always me that ends up getting wet....
> --------------------------------------------------------------------------
-
>---
>| Author for Pinnacle Publishing "Visual C++ Developer"
>http://www.pinpub.com/ |
>| http://lucifer.lotus.com/jim/main.htm
>|
> --------------------------------------------------------------------------
-
>---



Wed, 02 Aug 2000 03:00:00 GMT  
 Catching Exceptions with catch(...): How do I get exception info?

On Sat, 14 Feb 1998 12:21:49 -0500, "Bruce E. Stemplewski"

Quote:

>I have an exception that is being thrown in my program.  I have no idea what
>type of exception it is.   I can catch it with catch(...).  Is there any why
>to get an error message from this exception or to determine what type it is?

No. Or depending on your point of view, maybe.

You can discover the exception type with the following, but it doesn't
work reliably in VC5 (tends to double-destruct objects caught by
reference):

catch (...)
{
   // Common code here...
   try
   {
      throw; // Really!
   }
   catch (CException*) {}
   catch (std::exception&) {}
   catch (...)
   {
      // Still can't determine exception type here.
   }

Quote:
}

Why would you want to do that? It can be useful if you have some
common code you want to be executed regardless of the exception
caught, but you still care about the specific type of exception, and
you can't factor the common code out into a separate function or rely
on resource-acquisition-is-initialization techniques, which usually
suffice.

--
Doug Harrison



Thu, 03 Aug 2000 03:00:00 GMT  
 Catching Exceptions with catch(...): How do I get exception info?

I tend not to use the global catch (catch(...) so I can't comment on that)
but this is code that I use all the time and it works fine

try
{
// do something that throws a CException based exception

Quote:
}

catch(CException* e)
{
 TCHAR szmsg[1024];
 e->GetErrorMessage( szmsg, 1024 * sizeof(TCHAR));
 AfxMessageBox(szmsg);

Quote:
}

if your catch clause isn't being called then it possible your not getting an
MFC exception but perhaps a WIN32 Structured Exception being thrown (which
is why the global catch to get called).  Look in the online help about
Structured Exception Handling (SEH)

--
Why isn't there mouse-flavored cat food?
 ---------------------------------------------------------------------------
---
| Author for Pinnacle Publishing "Visual C++ Developer"
http://www.pinpub.com/ |
| http://lucifer.lotus.com/jim/main.htm
|
 ---------------------------------------------------------------------------
---



Sun, 06 Aug 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Catching Win32 exceptions with a C++ catch-block

2. Q: Why try catch cannot catch the exception

3. Catching hardware exceptions using C++ exceptions

4. Catching SEC Exceptions as C++ Exceptions

5. Getting Exception Code withing catch{}

6. Getting information in a catch-all exception

7. Getting Exception Code withing catch(...)

8. How to catch this exception?

9. Catching Exception from BaseClass

10. Catching unmanaged exceptions in MC++

11. Catching exceptions thrown from another thread?

12. catching floating point exception - but where is it coming from

 

 
Powered by phpBB® Forum Software