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


C# Exception.SetErrorCode方法代码示例

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


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

示例1: WaitForMultipleObjects

        internal static unsafe int WaitForMultipleObjects(IntPtr* pHandles, int numHandles, bool waitAll, int millisecondsTimeout)
        {
            Debug.Assert(millisecondsTimeout >= -1);

            //
            // In the CLR, we use CoWaitForMultipleHandles to pump messages while waiting in an STA.  In that case, we cannot use WAIT_ALL.  
            // That's because the wait would only be satisfied if a message arrives while the handles are signalled.
            //
            if (waitAll)
            {
                if (numHandles == 1)
                    waitAll = false;
                else if (GetCurrentApartmentType() == ApartmentType.STA)
                    throw new NotSupportedException(SR.NotSupported_WaitAllSTAThread);
            }

            int result;
            if (ReentrantWaitsEnabled)
            {
                Debug.Assert(!waitAll);
                result = RuntimeImports.RhCompatibleReentrantWaitAny(false, millisecondsTimeout, numHandles, pHandles);
            }
            else
            {
                result = (int)Interop.mincore.WaitForMultipleObjectsEx((uint)numHandles, (IntPtr)pHandles, waitAll, (uint)millisecondsTimeout, false);
            }

            if (result == WAIT_FAILED)
            {
                int error = (int)Interop.mincore.GetLastError();
                switch (error)
                {
                    case Interop.mincore.Errors.ERROR_INVALID_PARAMETER:
                        throw new ArgumentException();

                    case Interop.mincore.Errors.ERROR_ACCESS_DENIED:
                        throw new UnauthorizedAccessException();

                    case Interop.mincore.Errors.ERROR_NOT_ENOUGH_MEMORY:
                        throw new OutOfMemoryException();

                    default:
                        Exception ex = new Exception();
                        ex.SetErrorCode(error);
                        throw ex;
                }
            }

            return result;
        }
开发者ID:justinvp,项目名称:corert,代码行数:50,代码来源:LowLevelThread.cs

示例2: EnsureHasMarshalProxy

        private static void EnsureHasMarshalProxy()
        {
            if (s_winRtMarshalProxy != null)
                return;

            try
            {
                IMarshal proxy;
                Int32 hr = Interop.mincore.RoGetBufferMarshaler(out proxy);
                s_winRtMarshalProxy = proxy;

                if (hr != HResults.S_OK)
                {
                    Exception ex = new Exception(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
                    ex.SetErrorCode(hr);
                    throw ex;
                }

                if (proxy == null)
                    throw new NullReferenceException(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
            }
            catch (DllNotFoundException ex)
            {
                throw new NotImplementedException(SR.Format(SR.NotImplemented_NativeRoutineNotFound,
                                                               String.Format("{0}!RoGetBufferMarshaler", WinTypesDLL)),
                                                  ex);
            }
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:28,代码来源:WindowsRuntimeBuffer.cs


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