This documentation is archived and is not being maintained.

WebException Constructor ()

.NET Framework 1.1

Initializes a new instance of the WebException class.

[Visual Basic]
Public Sub New()
[C#]
public WebException();
[C++]
public: WebException();
[JScript]
public function WebException();

Remarks

The default constructor initializes a new instance of the WebException class. The Message property is initialized to a system-supplied message that describes the error. This message takes into account the current system culture. The InnerException and Response properties are initialized to a null reference (Nothing in Visual Basic). The Status property is initialized to RequestCanceled.

Example

[Visual Basic, C#, C++] The following example throws a default WebException.

[Visual Basic] 
Try
    ' A 'Socket' object has been created.
    Dim httpSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
    
    ' The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method. 
     ' which leads to the 'SocketException' exception. 
    
    Dim hostEntry As IPHostEntry = Dns.Resolve("http://www.contoso.com")
    
    Dim serverAddress As IPAddress = hostEntry.AddressList(0)
    Dim endPoint As New IPEndPoint(serverAddress, 80)
    httpSocket.Connect(endPoint)
    Console.WriteLine("Connection created successfully")
    httpSocket.Close()
Catch e As SocketException
    Dim exp As [String] = e.Message
    ' Throw the WebException with no parameters.
    Throw New WebException()
End Try


[C#] 

          try   
          {
              // A 'Socket' object has been created.
              Socket httpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

              // The IPaddress of the unknown uri is resolved using the 'Dns.Resolve' method. 
              
              IPHostEntry hostEntry = Dns.Resolve("http://www.contoso.com");

              IPAddress serverAddress = hostEntry.AddressList[0];
              IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
              httpSocket.Connect(endPoint);
              Console.WriteLine("Connection created successfully");
              httpSocket.Close();
           }
         catch(SocketException e)
           {
              String exp = e.Message;    
              // Throw the WebException with no parameters.
              throw new WebException();
           }

[C++] 

      try {
         // A 'Socket' object has been created.
         Socket* httpSocket = new Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);

         // The IPaddress of the unknown uri is resolved using the 'Dns::Resolve' method.

         IPHostEntry* hostEntry = Dns::Resolve(S"http://www.contoso.com");

         IPAddress* serverAddress = hostEntry->AddressList[0];
         IPEndPoint* endPoint = new IPEndPoint(serverAddress, 80);
         httpSocket->Connect(endPoint);
         Console::WriteLine(S"Connection created successfully");
         httpSocket->Close();
      } catch (SocketException* e) {
         String*  exp = e->Message;
         // Throw the WebException with no parameters.
         throw new WebException();
      }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

WebException Class | WebException Members | System.Net Namespace | WebException Constructor Overload List

Show: