As we known, try...catch mechanism is a quite common feature for the high level languages like Java or C #. Although C + + proclaimed that it supports this mechanism, the memory management limitation of C + + makes this try...catch f Unction is weak.
C + + cannot automatically captures the exception like C # or Java, so in case of exception happens, we must throw explicitly .
//Exceptions #include <iostream>usingnamespace std;
int
Char* pEx = 0;
...
try
throw
catch (
int
"An exception occurred. Exception Nr. "
‘\n‘; }
return 0;
}
But if we is coding with managed and unmanaged code, what to handle the exception?
Actually for the managed part try block no doubt can capture the exception, for the UN managed part we can use one special The.
Try catching using the ExternalException class
The base exception type for all COM Interop exceptions and structured exception handling (SEH) exceptions.
[SerializableAttribute] [ComVisibleAttribute (true)]
Public ref class Public SystemException
As the sample above, makes your target clause derived from ExternalException class, then internally the function can CAPTU Re the exception.
How to handle exception in managed code and unmanaged code