简体   繁体   English

抛出COMException但未陷入C#

[英]COMException thrown but not caught in C#

I have the following code to trigger on a button click: 我有以下代码可在单击按钮时触发:

        private void buttonConnect_Click(object sender, EventArgs e)
    {
        _BMDSwitcherConnectToFailure failReason = 0;
        string address = textBoxIP.Text;

        try
        {
            // Note that ConnectTo() can take several seconds to return, both for success or failure,
            // depending upon hostname resolution and network response times, so it may be best to
            // do this in a separate thread to prevent the main GUI thread blocking.
            m_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);
        }
        catch (COMException)
        {
            // An exception will be thrown if ConnectTo fails. For more information, see failReason.
            switch (failReason)
            {
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureNoResponse:
                    MessageBox.Show("No response from Switcher. Are you sure the IP is correct?", "Error");
                    break;
                case _BMDSwitcherConnectToFailure.bmdSwitcherConnectToFailureIncompatibleFirmware:
                    MessageBox.Show("Switcher has incompatible firmware", "Error");
                    break;
                default:
                    MessageBox.Show("Connection failed for unknown reason", "Error");
                    break;
            }
            return;
        }

        SwitcherConnected();
    }

I noticed that when on a different machine, the program wouldn't run. 我注意到,当在另一台计算机上时,该程序将无法运行。 I setup VS to break on the specific error and I get this: 我将VS设置为打破特定错误,我得到了:

Exception thrown: 'System.Runtime.InteropServices.COMException'

Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

It throws this on the following line: 它将其抛出以下行:

_switcherDiscovery.ConnectTo(address, out m_switcher, out failReason);

I'm struggling to figure out what this exception isn't caught by the code. 我正在努力找出代码未捕获到此异常的原因。

Check in Visual Studio debug options that you have this Exception type selected: 在Visual Studio调试选项中签入您选中此异常类型的选项:

Debug - > Exceptions 调试->异常

Expand the CLRE (Common Language Runtime Exceptions) 展开CLRE(公共语言运行时异常)

Then expand - System.Runtime.InteropServices 然后展开-System.Runtime.InteropServices

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM