/// <summary> /// Throws the correct Site Destination exception for a given WinInet Error Code. /// This attempts to map common WinInet errors to corresponding Destination errors. /// </summary> /// <param name="error">The WinInet error code</param> private void ThrowDestinationException(int error) { // Exception detail data string exceptionType = null; string extendedMessage = WinInet.GetExtendedInfo(); if (extendedMessage == null || extendedMessage == String.Empty) { extendedMessage = "The source of the error is unknown."; } SiteDestinationException exception = null; // This wraps the lower level WinInet errors into higher level // Site destination exceptions. It also gathers extended info from // the connection to assist with troubleshooting. switch (error) { case ERROR_INTERNET.CANNOT_CONNECT: exceptionType = SiteDestinationException.ConnectionException; break; case ERROR_INTERNET.NAME_NOT_RESOLVED: exceptionType = SiteDestinationException.ConnectionException; break; case ERROR_INTERNET.ITEM_NOT_FOUND: exceptionType = SiteDestinationException.TransferException; break; case ERROR_INTERNET.TIMEOUT: exceptionType = SiteDestinationException.TransferException; break; case ERROR_INTERNET.LOGIN_FAILURE: exception = new LoginException(null, error); break; case ERROR_INTERNET.INCORRECT_PASSWORD: exception = new LoginException(null, error); break; case ERROR_INTERNET.INCORRECT_USER_NAME: exception = new LoginException(null, error); break; case ERROR_INTERNET.EXTENDED_ERROR: exceptionType = SiteDestinationException.UnexpectedException; break; default: exceptionType = SiteDestinationException.UnexpectedException; break; } // Set up a sitedestination exception with the correct information if (exception == null) { exception = new SiteDestinationException( null, exceptionType, GetType().Name, error); } exception.DestinationErrorCode = error; exception.DestinationType = GetType().Name; exception.DestinationExtendedMessage = extendedMessage; // throw it throw exception; }