处理来自COM api的致命异常

时间:2013-06-19 09:39:14

标签: c# exception com

我有以下代码片段,它调用COM接口api(MS Mobile API)

try
{
    MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
    IMbnInterfaceManager infMgr = (IMbnInterfaceManager)mbnInfMgr;

    IMbnInterface[] interfaces = (IMbnInterface[])infMgr.GetInterfaces();
    ///
    /// NOTE: Will throw exception here if no Adapter Present - "Service not Started"
    ///
    foreach (IMbnInterface mobileInterface in interfaces)
    {
        MBN_INTERFACE_CAPS caps = mobileInterface.GetInterfaceCapability();
        MBN_READY_STATE readyState = mobileInterface.GetReadyState();
        IMbnRadio radio = (IMbnRadio)mobileInterface;

        MBN_PROVIDER provider = mobileInterface.GetHomeProvider();
        ///
        /// NOTE: Will throw exception here if no SIM Present.
        ///

COM例外处理如下

///
/// Handle COM Exceptions 
///
catch (System.Runtime.InteropServices.COMException ex)
{
    switch ((uint)ex.ErrorCode)
    {
        case 0x8054820A:
             // ...
             break;

        case 0x80070490:
             // ...
             break;

             default:
             string str = "COM: " + ex.Message;
             break;
    }
}

我遇到的问题是,并非所有例外情况都是致命的,如“无SIM卡”例外,我仍然需要 访问已创建的COM接口组件,但异常终止所有这些实例。

我应该如何解决这个问题,还是我必须再次完成构建过程?

感谢您的任何建议

Sarah T

0 个答案:

没有答案