cody said:
I have always bee wondering how a C++ programm can determine which type an
Exception is.
Hmmm., it's been so long since I've written anything in C++.....
As I recall, there was a way to map 32 bit exception codes into C++ types.
Use the method _set_se_translator to tell the runtime to call your mapping
method when an exception occurs. I used to use this but its been years, so
my memory has definitely faded. But you have to do the work yourself.
Anyway, I don't know of any .net app written in a high level language that
can even throw an exception that is not derived from System.Exception. There
may be something out there that does but it would definitely be an oddball.
An int does not support rtti so how can the system know? Even if the
Exception includes something
like a typeid, is is guaranteed to be the same on all compilers? Then
somewhere must all typeid's of the primitive types be defined.
I think you're thinking of this in MFC terms (rtti?). Come over to the dark
side, start coding in C#.....
Anyway, if all you have are untyped exceptions (win32 seh) then your code
has to look at the actual exception code and try to figure out from that
what it means. (e.g. 0xC0000005 == ACCESS VIOLATION, also known as a null
pointer) There's a reason why .net does not use that model - it's damn hard
to use. C++ was better, but you typically had the worst of all worlds,
because some errors (e.g. COM) manifested themselves as sentinel return
values from methods (for which there is no standard return value to signal a
failure), some errors where thrown as C++ types, others as untyped win32 SEH
exceptions, some methods used SetLastError(), etc.
..NET exception handling unifies the error handling model - one size catches
all. Unless someone insists on writing code that uses one of the other means
of reporting error conditions.