>>>>What's the CLI equivalent of the empty catch?
>>>>
>>>>i.e.
>>>>try{}
>>>>catch
>>>>{}
>>
>It's allowed in C#. It's equivalent to the C++/CLI construct:
>>
>try
>{
>}
>catch(Exceptio n^)
>{
>}
>
No. "catch(Exceptio n^)" is *not* the same as "catch" in C#!
>
"catch(Exceptio n^)" will *only* catch exceptions which are derived from
"System.Excepti on"!
>
"catch" will catch *all* Exceptions (derived from "System.Object" )!
It also will catch native exceptins in C#!!!
Egads!
I'd forgotten that the CLR actually supporting throwing something not
derived from System.Exceptio n!
>
Wouldn't catch (Exception^) do so as well, giving an SEHException? Or is
that only for p/invoke?
SEHException is also derived from "System.Excepti on". But you can throw
*any* object as an exception. Therefor, if you want to catch *all*
exceptions, you need to catch "System.Obj ect" instead of "System.Excepti on"!
"Jochen Kalmbach [MVP]" <nospam-Jochen.Kalmbach @holzma.dewrote in message
news:enBVzKQnHH A.4628@TK2MSFTN GP06.phx.gbl...
Hi Ben!
>>It also will catch native exceptins in C#!!!
>>
>Wouldn't catch (Exception^) do so as well, giving an SEHException? Or is
>that only for p/invoke?
>
SEHException is also derived from "System.Excepti on". But you can throw
*any* object as an exception. Therefor, if you want to catch *all*
exceptions, you need to catch "System.Obj ect" instead of
"System.Excepti on"!
>
See:
I wasn't doubting that catching System.Object will catch all exceptions...
but wouldn't catching System.Exceptio n also catch all exceptions, decoding
managed objects derived from Exception, and wrapping everything else in
SEHException?
I wasn't doubting that catching System.Object will catch all exceptions...
but wouldn't catching System.Exceptio n also catch all exceptions, decoding
managed objects derived from Exception, and wrapping everything else in
SEHException?
I don't understand the background of this question?
I don't know the internals of every assembly; so I don't know if
"System.Excepti on" will catch *all* exceptions... regardless of
SEHException...
>I wasn't doubting that catching System.Object will catch all exceptions...
>but wouldn't catching System.Exceptio n also catch all exceptions, decoding
>managed objects derived from Exception, and wrapping everything else in
>SEHException ?
>
>I don't understand the background of this question?
>
>I don't know the internals of every assembly; so I don't know if
>"System.Except ion" will catch *all* exceptions... regardless of
>SEHException.. .
You can also use the RuntimeCompatib ilityAttribute on your assembly
with WrapNonExceptio nThrows = true to make sure all exceptions you see
are derived from Exception (if they aren't already, they get wrapped
in a RuntimeWrappedE xception). That's what C# does for example.
Comment