public static Exception TryConvertWin32ExceptionToIOException()

in DbgProvider/internal/Util.cs [1422:1506]


        public static Exception TryConvertWin32ExceptionToIOException( Win32Exception w32e, MulticulturalString errorMsg )
        {
            int errorCode = w32e.NativeErrorCode;
            if( errorCode < 0 )
            {
                const int HRESULT_WITH_FACILITY_WIN32 = unchecked( (int) 0x80070000 );
                if( HRESULT_WITH_FACILITY_WIN32 == (errorCode & 0xffff0000) )
                {
                    errorCode = errorCode & 0x0000ffff;
                }
            }

            if( 0 == errorCode )
            {
                throw new ArgumentException( "The error code does not indicate an error.", "w32e" );
            }

            // Log the en-us and localized message.
            LogManager.Trace( "Win32 IO Error {0}: {1} ({2})", errorCode, errorMsg, errorMsg.ToString() );

            const int ERROR_FILE_NOT_FOUND = 2;
            const int ERROR_PATH_NOT_FOUND = 3;
            const int ERROR_ACCESS_DENIED = 5;
            const int ERROR_INVALID_DRIVE = 15;
            const int ERROR_SHARING_VIOLATION = 32;
            const int ERROR_LOCK_VIOLATION = 33;
            const int ERROR_HANDLE_EOF = 38;
            const int ERROR_HANDLE_DISK_FULL = 39;
            const int ERROR_FILE_EXISTS = 80;
            const int ERROR_CANNOT_MAKE = 82;
            const int ERROR_INVALID_PARAMETER = 87;
            const int ERROR_OPEN_FAILED = 110;
            const int ERROR_DISK_FULL = 112;
            const int ERROR_CALL_NOT_IMPLEMENTED = 120;
            const int ERROR_INVALID_NAME = 123;
            const int ERROR_NEGATIVE_SEEK = 131;
            const int ERROR_DIR_NOT_EMPTY = 145;
            const int ERROR_PATH_BUSY = 148;
            const int ERROR_BAD_ARGUMENTS = 160;
            const int ERROR_BAD_PATHNAME = 161;
            const int ERROR_ALREADY_EXISTS = 183;
            const int ERROR_FILENAME_EXCED_RANGE = 206;
            const int ERROR_OPERATION_ABORTED = 995;

            switch( errorCode )
            {
                case NativeMethods.ERROR_INVALID_DATA:
                    return new InvalidDataException( errorMsg, w32e );
                case ERROR_FILE_EXISTS:
                case ERROR_SHARING_VIOLATION:
                case ERROR_LOCK_VIOLATION:
                case ERROR_HANDLE_DISK_FULL:
                case ERROR_CANNOT_MAKE:
                case ERROR_OPEN_FAILED:
                case ERROR_DISK_FULL:
                case ERROR_INVALID_NAME:
                case ERROR_NEGATIVE_SEEK:
                case ERROR_DIR_NOT_EMPTY:
                case ERROR_PATH_BUSY:
                case ERROR_BAD_PATHNAME:
                case ERROR_ALREADY_EXISTS:
                    return new IOException( errorMsg, w32e );
                case ERROR_FILE_NOT_FOUND:
                    return new FileNotFoundException( errorMsg, w32e );
                case ERROR_PATH_NOT_FOUND:
                    return new DirectoryNotFoundException( errorMsg, w32e );
                case ERROR_ACCESS_DENIED:
                    return new UnauthorizedAccessException( errorMsg, w32e );
                case ERROR_INVALID_DRIVE:
                    return new System.IO.DriveNotFoundException( errorMsg, w32e );
                case ERROR_HANDLE_EOF:
                    return new EndOfStreamException( errorMsg, w32e );
                case ERROR_INVALID_PARAMETER:
                case ERROR_BAD_ARGUMENTS:
                    return new ArgumentException( errorMsg, w32e );
                case ERROR_CALL_NOT_IMPLEMENTED:
                    return new NotImplementedException( errorMsg, w32e );
                case ERROR_FILENAME_EXCED_RANGE:
                    return new PathTooLongException( errorMsg, w32e );
                case ERROR_OPERATION_ABORTED:
                    return new OperationCanceledException( errorMsg, w32e );
                default:
                    return null;
            }
        } // end TryConvertWin32ExceptionToIOException()