我的 C# 代码使用一个 COM 对象。有时 COM 对象方法会返回E_OUTOFMEMORY,但它会被翻译成System.OutOfMemoryException而不是System.Runtime.InteropServices.COMException适当的ErrorCode. 这对我来说是个问题,因为它使我的错误处理变得复杂——我希望所有由 COM 对象方法引起的错误指示都被抛出System.Runtime.InteropServices.COMException。
当 COM 对象方法返回时,是否可以始终拥有System.Runtime.InteropServices.COMException而不是?System.OutOfMemoryExceptionE_OUTOFMEMORY