다음을 통해 공유


WebException 생성자

정의

WebException 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
WebException()

WebException 클래스의 새 인스턴스를 초기화합니다.

WebException(String)

지정된 오류 메시지를 사용하여 클래스의 WebException 새 인스턴스를 초기화합니다.

WebException(SerializationInfo, StreamingContext)
사용되지 않음.

지정된 인스턴스와 StreamingContext 인스턴스에서 클래스의 WebException 새 인스턴스를 SerializationInfo 초기화합니다.

WebException(String, WebExceptionStatus)

지정된 오류 메시지 및 상태를 사용하여 클래스의 WebException 새 인스턴스를 초기화합니다.

WebException(String, Exception)

지정된 오류 메시지와 중첩된 예외를 WebException 사용하여 클래스의 새 인스턴스를 초기화합니다.

WebException(String, Exception, WebExceptionStatus, WebResponse)

지정된 오류 메시지, 중첩된 예외, 상태 및 응답을 사용하여 클래스의 WebException 새 인스턴스를 초기화합니다.

WebException()

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

WebException 클래스의 새 인스턴스를 초기화합니다.

public:
 WebException();
public WebException();
Public Sub New ()

예제

다음 예제에서는 기본값 WebException을 throw합니다.


 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();
  }
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

설명

매개 변수가 없는 생성자는 클래스의 새 인스턴스를 WebException 초기화합니다. 이 Message 속성은 오류를 설명하는 시스템 제공 메시지로 초기화됩니다. 이 메시지는 현재 시스템 문화권을 고려합니다. 및 Response 속성은 InnerException .로 null초기화됩니다. Status 속성이 RequestCanceled으로 초기화됩니다.

적용 대상

WebException(String)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지를 사용하여 클래스의 WebException 새 인스턴스를 초기화합니다.

public:
 WebException(System::String ^ message);
public WebException(string message);
public WebException(string? message);
new System.Net.WebException : string -> System.Net.WebException
Public Sub New (message As String)

매개 변수

message
String

오류 메시지의 텍스트입니다.

예제

다음 예제 WebException 에서는 오류 메시지를 지정하여 throw합니다.

 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(connectUri);

     IPAddress serverAddress = hostEntry.AddressList[0];
     IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
     httpSocket.Connect(endPoint);
     Console.WriteLine("Connection created successfully");
     httpSocket.Close();
  }
catch(SocketException e)
  {		     
     Console.WriteLine("\nException thrown.\nThe Original Message is: "+e.Message);
     // Throw the 'WebException' object with a message string specific to the situation.
     throw new WebException("Unable to locate the Server with 'www.contoso.com' Uri.");
  }

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. 
     
    Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
    
    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
    Console.WriteLine((ControlChars.Cr + "Exception thrown." + ControlChars.Cr + "The Original Message is: " + e.Message))
    ' Throw the 'WebException' object with a message string specific to the situation.
    Throw New WebException("Unable to locate the Server with 'www.contoso.com' Uri.")
End Try

설명

인스턴스는 WebException 속성이 Messagemessage으로 설정된 상태에서 초기화됩니다. 이 nullMessage 경우 message 속성은 시스템 제공 메시지로 초기화됩니다. 및 Response 속성은 InnerException .로 null초기화됩니다. Status 속성이 RequestCanceled으로 초기화됩니다.

추가 정보

적용 대상

WebException(SerializationInfo, StreamingContext)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

주의

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

지정된 인스턴스와 StreamingContext 인스턴스에서 클래스의 WebException 새 인스턴스를 SerializationInfo 초기화합니다.

protected:
 WebException(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected WebException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
protected WebException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Net.WebException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebException
new System.Net.WebException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebException
Protected Sub New (serializationInfo As SerializationInfo, streamingContext As StreamingContext)

매개 변수

serializationInfo
SerializationInfo

WebException항목을 serialize하는 데 필요한 정보가 들어 있는 A SerializationInfo 입니다.

streamingContext
StreamingContext

WebException스트림과 연결된 serialize된 스트림의 원본을 포함하는 A StreamingContext 입니다.

특성

설명

이 생성자는 클래스에 ISerializable 대한 인터페이스를 구현합니다 WebException .

추가 정보

적용 대상

WebException(String, WebExceptionStatus)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지 및 상태를 사용하여 클래스의 WebException 새 인스턴스를 초기화합니다.

public:
 WebException(System::String ^ message, System::Net::WebExceptionStatus status);
public WebException(string message, System.Net.WebExceptionStatus status);
public WebException(string? message, System.Net.WebExceptionStatus status);
new System.Net.WebException : string * System.Net.WebExceptionStatus -> System.Net.WebException
Public Sub New (message As String, status As WebExceptionStatus)

매개 변수

message
String

오류 메시지의 텍스트입니다.

status
WebExceptionStatus

값 중 WebExceptionStatus 하나입니다.

예제

다음 예제에서는 오류 메시지와 를 WebException 지정하여 throw합니다 WebExceptionStatus.


 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)
  {
      Console.WriteLine("\nException thrown.\nThe Original Message is: "+e.Message);
      // Throw the 'WebException' object with a message string and message status specific to the situation.
      throw new WebException("Unable to locate the Server with 'www.contoso.com' Uri.",WebExceptionStatus.NameResolutionFailure);
  }

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. 
     
    Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
    
    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
    Console.WriteLine((ControlChars.Cr + "Exception thrown." + ControlChars.Cr + "The Original Message is: " + e.Message))
    ' Throw the 'WebException' object with a message string and message status specific to the situation.
    Throw New WebException("Unable to locate the Server with 'www.contoso.com' Uri.", WebExceptionStatus.NameResolutionFailure)
End Try

설명

인스턴스는 WebException 속성이 Message 값으로 설정되고 속성이 Statusmessage 으로 설정된 상태에서 status초기화됩니다. 이 nullMessage 경우 message 속성은 시스템 제공 메시지로 초기화됩니다. 및 Response 속성은 InnerException .로 null초기화됩니다.

적용 대상

WebException(String, Exception)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지와 중첩된 예외를 WebException 사용하여 클래스의 새 인스턴스를 초기화합니다.

public:
 WebException(System::String ^ message, Exception ^ inner);
public:
 WebException(System::String ^ message, Exception ^ innerException);
public WebException(string message, Exception inner);
public WebException(string? message, Exception? innerException);
public WebException(string message, Exception innerException);
new System.Net.WebException : string * Exception -> System.Net.WebException
new System.Net.WebException : string * Exception -> System.Net.WebException
Public Sub New (message As String, inner As Exception)
Public Sub New (message As String, innerException As Exception)

매개 변수

message
String

오류 메시지의 텍스트입니다.

innerinnerException
Exception

중첩된 예외입니다.

예제

다음 예제에서는 오류 메시지 및 중첩된 예외를 지정하여 throw WebException 합니다.


   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(connectUri);

          IPAddress serverAddress = hostEntry.AddressList[0];
          IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
          httpSocket.Connect(endPoint);
          Console.WriteLine("Connection created successfully");
          httpSocket.Close();		 
    }
  catch(SocketException e)
{ 
       Console.WriteLine("\nException thrown.\nThe Original Message is: "+e.Message);
       //  Throw the 'WebException' object with a message string specific to the situation; 
          //  and the 'InnerException' which actually lead to this exception.
          throw new WebException("Unable to locate the Server with 'www.contoso.com' Uri.",e);
    }

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. 
     Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
    
    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
    Console.WriteLine((ControlChars.Cr + "Exception thrown." + ControlChars.Cr + "The Original Message is: " + e.Message))
    ' Throw the 'WebException' object with a message string specific to the situation. 
     ' and the 'InnerException' which actually lead to this exception.
    Throw New WebException("Unable to locate the Server with 'www.contoso.com' Uri.", e)
End Try

설명

인스턴스는 WebException 속성이 Message 값으로 설정되고 속성이 InnerExceptionmessage 으로 설정된 상태에서 innerException초기화됩니다. 이 nullMessage 경우 message 속성은 시스템 제공 메시지로 초기화됩니다. 및 Response 속성은 InnerException .로 null초기화됩니다. Status 속성이 RequestCanceled으로 초기화됩니다.

추가 정보

적용 대상

WebException(String, Exception, WebExceptionStatus, WebResponse)

Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs
Source:
WebException.cs

지정된 오류 메시지, 중첩된 예외, 상태 및 응답을 사용하여 클래스의 WebException 새 인스턴스를 초기화합니다.

public:
 WebException(System::String ^ message, Exception ^ inner, System::Net::WebExceptionStatus status, System::Net::WebResponse ^ response);
public:
 WebException(System::String ^ message, Exception ^ innerException, System::Net::WebExceptionStatus status, System::Net::WebResponse ^ response);
public WebException(string message, Exception inner, System.Net.WebExceptionStatus status, System.Net.WebResponse response);
public WebException(string? message, Exception? innerException, System.Net.WebExceptionStatus status, System.Net.WebResponse? response);
public WebException(string message, Exception innerException, System.Net.WebExceptionStatus status, System.Net.WebResponse response);
new System.Net.WebException : string * Exception * System.Net.WebExceptionStatus * System.Net.WebResponse -> System.Net.WebException
new System.Net.WebException : string * Exception * System.Net.WebExceptionStatus * System.Net.WebResponse -> System.Net.WebException
Public Sub New (message As String, inner As Exception, status As WebExceptionStatus, response As WebResponse)
Public Sub New (message As String, innerException As Exception, status As WebExceptionStatus, response As WebResponse)

매개 변수

message
String

오류 메시지의 텍스트입니다.

innerinnerException
Exception

중첩된 예외입니다.

status
WebExceptionStatus

값 중 WebExceptionStatus 하나입니다.

response
WebResponse

WebResponse 원격 호스트의 응답을 포함하는 인스턴스입니다.

예제

다음 예제에서는 오류 메시지와 를 WebException 지정하여 throw합니다 WebExceptionStatus.

      // Send the data. 
      Encoding ASCII = Encoding.ASCII;
      string requestPage = "GET /nhjj.htm HTTP/1.1\r\nHost: " + connectUri + "\r\nConnection: Close\r\n\r\n";
      Byte[] byteGet = ASCII.GetBytes(requestPage);
      Byte[] recvBytes = new Byte[256];

      // Create an 'IPEndPoint' object.
 
      IPHostEntry hostEntry = Dns.Resolve(connectUri);
      IPAddress serverAddress = hostEntry.AddressList[0];
      IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);

      // Create a 'Socket' object  for sending data.
      Socket connectSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp);
 
      // Connect to host using 'IPEndPoint' object.

      connectSocket.Connect(endPoint);
 
      // Sent the 'requestPage' text to the host.
      connectSocket.Send(byteGet, byteGet.Length, 0);
 
      // Receive the information sent by the server.
      Int32 bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0);
      String headerString = ASCII.GetString(recvBytes, 0, bytesReceived);

     // Check whether 'status 404' is there or not in the information sent by server.
     if(headerString.IndexOf("404")!=-1)
     {	 
         bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0);
         MemoryStream memoryStream = new MemoryStream(recvBytes);
         getStream = (Stream) memoryStream;
 
         // Create a 'WebResponse' object
         WebResponse myWebResponse = (WebResponse) new HttpConnect(getStream);
         Exception myException = new Exception("File Not found");

         // Throw the 'WebException' object with a message string, message status,InnerException and WebResponse
         throw new WebException("The Requested page is not found.",myException,WebExceptionStatus.ProtocolError,myWebResponse);
     }

     connectSocket.Close();

     ' Send the data. 
       Dim ASCII As Encoding = Encoding.ASCII
       Dim requestPage As String = "GET /nhjj.htm HTTP/1.1" + ControlChars.Lf + ControlChars.Cr + "Host: " + connectUri + ControlChars.Lf + ControlChars.Cr + "Connection: Close" + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr
       Dim byteGet As [Byte]() = ASCII.GetBytes(requestPage)
       Dim recvBytes(256) As [Byte]
       
       ' Create an 'IPEndPoint' object.
       Dim hostEntry As IPHostEntry = Dns.Resolve(connectUri)
       Dim serverAddress As IPAddress = hostEntry.AddressList(0)
       Dim endPoint As New IPEndPoint(serverAddress, 80)
       
       ' Create a 'Socket' object  for sending data.
       Dim connectSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
       
       ' Connect to host using 'IPEndPoint' object.
       connectSocket.Connect(endPoint)
       
       ' Sent the 'requestPage' text to the host.
       connectSocket.Send(byteGet, byteGet.Length, 0)
       
       ' Receive the information sent by the server.
       Dim bytesReceived As Int32 = connectSocket.Receive(recvBytes, recvBytes.Length, 0)
       Dim headerString As [String] = ASCII.GetString(recvBytes, 0, bytesReceived)
      
       ' Check whether 'status 404' is there or not in the information sent by server.
       If headerString.IndexOf("404") <> False Then
           bytesReceived = connectSocket.Receive(recvBytes, recvBytes.Length, 0)
           Dim memoryStream As New MemoryStream(recvBytes)
           getStream = CType(memoryStream, Stream)
           
           ' Create a 'WebResponse' object.
           Dim myWebResponse As WebResponse = CType(New HttpConnect(getStream), WebResponse)
           Dim myException As New Exception("File Not found")
           
           ' Throw the 'WebException' object with a message string, message status,InnerException and WebResponse.
           Throw New WebException("The Requested page is not found.", myException, WebExceptionStatus.ProtocolError, myWebResponse)
       End If 

       connectSocket.Close()

설명

인스턴스는 WebException 속성이 값message으로 Message 설정되고, InnerException 속성이 값innerException으로 설정되고, 속성이 값status으로 설정되고Response, Status 속성이 값response으로 설정된 상태에서 초기화됩니다. 이 nullMessage 경우 message 속성은 시스템 제공 메시지로 초기화됩니다.

적용 대상