WebException::Status Property
.NET Framework (current version)
Gets the status of the response.
Assembly: System (in System.dll)
The Status property indicates the reason for the WebException.
The value of Status is one of the WebExceptionStatus values.
Warning |
|---|
The ProxyNameResolutionFailure error is not returned to Windows 8.x Store apps. |
The following example checks the Status property and prints to the console the StatusCode and StatusDescription of the underlying HttpWebResponse instance.
try { // Create a web request for an unknown server (this raises the WebException). HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)(WebRequest::Create( "http://unknown.unknown.com" )); // Get the associated response for the above request. HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)(myHttpWebRequest->GetResponse()); myHttpWebResponse->Close(); } catch ( WebException^ e ) { Console::WriteLine( "This program is expected to throw WebException on successful run." + "\n\nException Message : " + e->Message ); if ( e->Status == WebExceptionStatus::ProtocolError ) { Console::WriteLine( "Status Code: {0}", ( (HttpWebResponse^)(e->Response) )->StatusCode ); Console::WriteLine( "Status Description: {0}", ( (HttpWebResponse^)(e->Response) )->StatusDescription ); } } catch ( Exception^ e ) { Console::WriteLine( e->Message ); }
Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Show:
