<bdo id='fxbwU'></bdo><ul id='fxbwU'></ul>
  • <small id='fxbwU'></small><noframes id='fxbwU'>

  • <legend id='fxbwU'><style id='fxbwU'><dir id='fxbwU'><q id='fxbwU'></q></dir></style></legend>

      1. <i id='fxbwU'><tr id='fxbwU'><dt id='fxbwU'><q id='fxbwU'><span id='fxbwU'><b id='fxbwU'><form id='fxbwU'><ins id='fxbwU'></ins><ul id='fxbwU'></ul><sub id='fxbwU'></sub></form><legend id='fxbwU'></legend><bdo id='fxbwU'><pre id='fxbwU'><center id='fxbwU'></center></pre></bdo></b><th id='fxbwU'></th></span></q></dt></tr></i><div id='fxbwU'><tfoot id='fxbwU'></tfoot><dl id='fxbwU'><fieldset id='fxbwU'></fieldset></dl></div>
        <tfoot id='fxbwU'></tfoot>

        捕获 COMException 特定的错误代码

        Catching COMException specific Error Code(捕获 COMException 特定的错误代码)

          <i id='SgGHI'><tr id='SgGHI'><dt id='SgGHI'><q id='SgGHI'><span id='SgGHI'><b id='SgGHI'><form id='SgGHI'><ins id='SgGHI'></ins><ul id='SgGHI'></ul><sub id='SgGHI'></sub></form><legend id='SgGHI'></legend><bdo id='SgGHI'><pre id='SgGHI'><center id='SgGHI'></center></pre></bdo></b><th id='SgGHI'></th></span></q></dt></tr></i><div id='SgGHI'><tfoot id='SgGHI'></tfoot><dl id='SgGHI'><fieldset id='SgGHI'></fieldset></dl></div>

          <small id='SgGHI'></small><noframes id='SgGHI'>

                  <tbody id='SgGHI'></tbody>

                  <bdo id='SgGHI'></bdo><ul id='SgGHI'></ul>
                • <legend id='SgGHI'><style id='SgGHI'><dir id='SgGHI'><q id='SgGHI'></q></dir></style></legend><tfoot id='SgGHI'></tfoot>
                  本文介绍了捕获 COMException 特定的错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望有人可以帮助我.我有一个来自 COM 的特定异常,我需要捕获它然后尝试做其他事情,所有其他的都应该被忽略.我的异常错误消息是:

                  I'm hoping someone can help me. I've got a specific Exception from COM that I need to catch and then attempt to do something else, all others should be ignored. My error message with the Exception is:

                  System.Runtime.InteropServices.COMException(0x800A03EC):Microsoft Office Excel无法访问文件C: est.xls".有几个可能的原因:

                  System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file 'C: est.xls'. There are several possible reasons:

                  所以我最初的尝试是

                  try
                  {
                   // something
                  }
                  catch (COMException ce)
                  {
                     if (ce.ErrorCode == 0x800A03EC)
                     {
                        // try something else 
                     }
                  }
                  

                  然后我读到了编译器警告:

                  However then I read a compiler warning:

                  警告 22 与积分比较常数是无用的;常数是超出类型范围'int' .....ExcelReader.cs 629 21

                  Warning 22 Comparison to integral constant is useless; the constant is outside the range of type 'int' .....ExcelReader.cs 629 21

                  现在我知道 0x800A03EC 是HResult,我刚刚在 MSDN 上看过并阅读:

                  Now I know the 0x800A03EC is the HResult and I've just looked on MSDN and read:

                  HRESULT 是一个 32 位的值,分为三个不同的领域:严重性代码、设施代码和错误代码.严重性代码表示是否返回值表示信息、警告或错误.设施代码标识负责的系统区域错误.

                  HRESULT is a 32-bit value, divided into three different fields: a severity code, a facility code, and an error code. The severity code indicates whether the return value represents information, warning, or error. The facility code identifies the area of the system responsible for the error.

                  所以我的最终问题是,我如何确保捕获该特定异常?或者如何从 HResult 中获取错误代码?

                  So my ultimate question, is how do I ensure that I trap that specific exception? Or how do I get the error code from the HResult?

                  提前致谢.

                  推荐答案

                  ErrorCode 应该是一个无符号整数;您可以按如下方式进行比较:

                  The ErrorCode should be an unsigned integer; you can perform the comparison as follows:

                  try {
                      // something
                  } catch (COMException ce) {
                      if ((uint)ce.ErrorCode == 0x800A03EC) {
                          // try something else 
                      }
                  }
                  

                  这篇关于捕获 COMException 特定的错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                • <legend id='SyqKs'><style id='SyqKs'><dir id='SyqKs'><q id='SyqKs'></q></dir></style></legend>
                      <tbody id='SyqKs'></tbody>

                      <i id='SyqKs'><tr id='SyqKs'><dt id='SyqKs'><q id='SyqKs'><span id='SyqKs'><b id='SyqKs'><form id='SyqKs'><ins id='SyqKs'></ins><ul id='SyqKs'></ul><sub id='SyqKs'></sub></form><legend id='SyqKs'></legend><bdo id='SyqKs'><pre id='SyqKs'><center id='SyqKs'></center></pre></bdo></b><th id='SyqKs'></th></span></q></dt></tr></i><div id='SyqKs'><tfoot id='SyqKs'></tfoot><dl id='SyqKs'><fieldset id='SyqKs'></fieldset></dl></div>

                      • <tfoot id='SyqKs'></tfoot>

                            <bdo id='SyqKs'></bdo><ul id='SyqKs'></ul>

                            <small id='SyqKs'></small><noframes id='SyqKs'>