System.Exception.SetErrorCode C# (CSharp) Method

SetErrorCode() private method

private SetErrorCode ( int hr ) : void
hr int
return void
        internal void SetErrorCode(int hr)
        {
            HResult = hr;
        }
        

Usage Example

Example #1
0
        internal unsafe static int WaitForMultipleObjects(IntPtr* pHandles, int numHandles, bool waitAll, int millisecondsTimeout)
        {
            Contract.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)
            {
                Contract.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)
            {
                uint error = Interop.mincore.GetLastError();
                switch (error)
                {
                    case (uint)Interop.Constants.ErrorInvalidParameter:
                        throw new ArgumentException();

                    case (uint)Interop.Constants.ErrorAccessDenied:
                        throw new UnauthorizedAccessException();

                    case (uint)Interop.Constants.ErrorNotEnoughMemory:
                        throw new OutOfMemoryException();

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

            return result;
        }
All Usage Examples Of System.Exception::SetErrorCode