5.8. HRESULT-Exception Mapping
Problem
You need a reference table that maps each
COM HRESULT
to its managed exception counterpart. This
mapping will allow you to throw the correct managed exception in C#,
which will map to the expected COM HRESULT
in
unmanaged code.
Solution
Every managed exception maps to an HRESULT
. Table 5-2 lists the managed exception classes and their
equivalent HRESULT
values. Use this table to
determine what type of managed exception to use when throwing an
exception back to unmanaged code, as well as what type of exception
object to use when handling returned COM/COM+
HRESULT
values.
Table 5-2. Mappping .NET exceptions to HRESULTS
.NET exception class name |
HRESULT name (hex value of HRESULT) |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Get C# Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.