O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

P/Invoke Exceptions

Chapter 7, “Leveraging Existing Code—P/Invoke,” dealt with calls into unmanaged code using P/Invoke. Next, you will look specifically at what happens to exceptions that are generated from the unmanaged code.

If an exception is generated in unmanaged code, it is caught and translated to an appropriate managed exception and rethrown. The only exception would be when no appropriate managed exception exists to which to convert. You have already seen that throwing an unspecified exception such as the following

Throw;

results in an SEHException. In fact, any exception that is thrown that cannot be translated to its managed counterpart results in an SEHException.

A sample in the UnmanagedException directory raises four different ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required