hi all experts,


i have in my code a try block and it is throwing some exception. i am
catching that exception
in the catch(...) block . i don't know what type of exception is being
thrown and being caught in
that catch(...) block.


is there any way to know the type of exception that is being thrown in
the catch(...) block ???


thanks a lot
ravinder

Re: how to view the type of catch all (...) exception by Bruno

Bruno
Mon Feb 06 01:37:13 CST 2006

You can't, as far as I know.

personally, I think you shouldn't use catch(...) at all.
the reason is that catch(...) also eats SEH execptions.
i.e. dereferencing an invalid pointer, an array overflow or something else
will
get caught in catch(...).

since this might mean your program state is invalid (because of the illegal
operation).
there is no real way to recover.

I learned this via the book 'Debugging applications for Microsoft .NET and
microsoft windows' by John Robbins.
It convinced me that it is better to have an application crash than handle
an unkown exception. At least then you know immediatly that something has
gone wrong, instead of several minutes / hours later when (if) the
(possible)corruption triggers a real crash somewhere else.
If you can spare the $, this book is worth the money.

kind regards,
Bruno.


<ravinderthakur@gmail.com> wrote in message
news:1139210153.088630.16580@g44g2000cwa.googlegroups.com...
> hi all experts,
>
>
> i have in my code a try block and it is throwing some exception. i am
> catching that exception
> in the catch(...) block . i don't know what type of exception is being
> thrown and being caught in
> that catch(...) block.
>
>
> is there any way to know the type of exception that is being thrown in
> the catch(...) block ???
>
>
> thanks a lot
> ravinder
>



RE: how to view the type of catch all (...) exception by Thiru

Thiru
Mon Feb 06 01:40:21 CST 2006

Hi Ravinder,

You can use CException Class or If you are accessing any COM Interfaces use
COleException Class..

Sample Code
-----------------

int FunctionName( arg1, arg2 )
{
try
{

}
catch( CException cException )
{
cException.ReportError() //Pop's up the Error Message Box
cException.GetErrorMessage( szBuffer, _MAX_PATH )
}
}

-Thirumoorthi.

--
If you are not contributing to future, Future will not for you....


"ravinderthakur@gmail.com" wrote:

> hi all experts,
>
>
> i have in my code a try block and it is throwing some exception. i am
> catching that exception
> in the catch(...) block . i don't know what type of exception is being
> thrown and being caught in
> that catch(...) block.
>
>
> is there any way to know the type of exception that is being thrown in
> the catch(...) block ???
>
>
> thanks a lot
> ravinder
>
>

Re: how to view the type of catch all (...) exception by Alex

Alex
Mon Feb 06 02:51:23 CST 2006

Bruno van Dooren wrote:
>
> personally, I think you shouldn't use catch(...) at all.
> the reason is that catch(...) also eats SEH execptions.
> i.e. dereferencing an invalid pointer, an array overflow
> or something else will get caught in catch(...).

Fortunately, in VC2005 SEH and C++ exceptions are separated
at last. So, by default (/EHs) only C++ exceptions are
caught by catch(...).



Re: how to view the type of catch all (...) exception by Bruno

Bruno
Mon Feb 06 03:18:56 CST 2006

Hi Alex,

"Alex Blekhman" <tkfx.N05P4M@yahoo.com> wrote in message
news:e3IkDqvKGHA.2064@TK2MSFTNGP09.phx.gbl...
> Bruno van Dooren wrote:
>>
>> personally, I think you shouldn't use catch(...) at all.
>> the reason is that catch(...) also eats SEH execptions.
>> i.e. dereferencing an invalid pointer, an array overflow
>> or something else will get caught in catch(...).
>
> Fortunately, in VC2005 SEH and C++ exceptions are separated at last. So,
> by default (/EHs) only C++ exceptions are caught by catch(...).

Thanks. I Learned this with VC2003. Good thing they changed that.

I guess that takes some of the wind out of my argument...

Still, if your program catches ..., you still don't know what is going on,
so it's usefulness is limited.
Especially if you are dealing with 'physical resources' like files, devices,
databases etc, you cannot be
sure of your program state.

kind regards,
Bruno.




Re: how to view the type of catch all (...) exception by Alex

Alex
Mon Feb 06 03:44:00 CST 2006

Bruno van Dooren wrote:
> [...] if your program catches ..., you still don't know
> what is going on, so it's usefulness is limited.
> Especially if you are dealing with 'physical resources'
> like files, devices, databases etc, you cannot be
> sure of your program state.

That's the part I agree with you. catch(...) causes more
evil than good and should be used cautiously.



Re: how to view the type of catch all (...) exception by Eugene

Eugene
Mon Feb 06 04:09:26 CST 2006

ravinderthakur@gmail.com wrote:
> is there any way to know the type of exception that is being thrown in
> the catch(...) block ???

Yes there is but this is undocumented, subject to change and should only be
used for diagnostics/debugging purposes. See
http://www.windevnet.com/documents/win0212a/ (requires registration) for the
details.


--
Eugene
http://www.gershnik.com