当前位置: 首页>>代码示例>>C#>>正文


C# Exception.AddExceptionDataForRestrictedErrorInfo方法代码示例

本文整理汇总了C#中Exception.AddExceptionDataForRestrictedErrorInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.AddExceptionDataForRestrictedErrorInfo方法的具体用法?C# Exception.AddExceptionDataForRestrictedErrorInfo怎么用?C# Exception.AddExceptionDataForRestrictedErrorInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception.AddExceptionDataForRestrictedErrorInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AttachRestrictedErrorInfo

        /// <summary>
        /// Attach restricted error information to the exception if it may apply to that exception, returning
        /// back the input value
        /// </summary>
        internal static Exception AttachRestrictedErrorInfo(Exception e)
        {
            // If there is no exception, then the restricted error info doesn't apply to it
            if (e != null)
            {
                try
                {
                    // Get the restricted error info for this thread and see if it may correlate to the current
                    // exception object.  Note that in general the thread's IRestrictedErrorInfo is not meant for
                    // exceptions that are marshaled Windows.Foundation.HResults and instead are intended for
                    // HRESULT ABI return values.   However, in many cases async APIs will set the thread's restricted
                    // error info as a convention in order to provide extended debugging information for the ErrorCode
                    // property.
                    IRestrictedErrorInfo restrictedErrorInfo = Interop.mincore.GetRestrictedErrorInfo();
                    if (restrictedErrorInfo != null)
                    {
                        string description;
                        string restrictedDescription;
                        string capabilitySid;
                        int restrictedErrorInfoHResult;
                        restrictedErrorInfo.GetErrorDetails(out description,
                                                            out restrictedErrorInfoHResult,
                                                            out restrictedDescription,
                                                            out capabilitySid);

                        // Since this is a special case where by convention there may be a correlation, there is not a
                        // guarantee that the restricted error info does belong to the async error code.  In order to
                        // reduce the risk that we associate incorrect information with the exception object, we need
                        // to apply a heuristic where we attempt to match the current exception's HRESULT with the
                        // HRESULT the IRestrictedErrorInfo belongs to.  If it is a match we will assume association
                        // for the IAsyncInfo case.
                        if (e.HResult == restrictedErrorInfoHResult)
                        {
                            string errorReference;
                            restrictedErrorInfo.GetReference(out errorReference);

                            e.AddExceptionDataForRestrictedErrorInfo(restrictedDescription,
                                                                     errorReference,
                                                                     capabilitySid,
                                                                     restrictedErrorInfo);
                        }
                    }
                }
                catch
                {
                    // If we can't get the restricted error info, then proceed as if it isn't associated with this
                    // error.
                }
            }

            return e;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:56,代码来源:RestrictedErrorInfoHelper.cs


注:本文中的Exception.AddExceptionDataForRestrictedErrorInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。