Question:
Probably, one of the main questions that remain is how exactly the handling / display of exceptions from C ++ CLI code in C # code is done.
After all, the C ++ CLI combines managed and unmanaged code, and in addition is called from managed C # code.
How to correctly handle exceptions of C ++ CLI code on the C # side:
-
If
try\catch
blocks from<exception>
not placed in the managed part of CLI code? -
If
try\catch
blocks from<exception>
are placed in the managed part of CLI code? Forward on? -
If on the side of the unmanaged code
AcсessViolation
knocks out, and in the managed part of the CLI this method is in thetry\catch
– will the application crash all the same?
Answer:
Throwing exceptions between libraries and languages should be avoided.
The reason is that C ++ does not have a fixed ABI, even different versions of the compiler can implement these things in different ways inside.
If you want reliable and portable code, localize exceptions within a single binary.