WebException コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > WebException コンストラクタの意味・解説 

WebException コンストラクタ (String, WebExceptionStatus)

WebException クラス新しインスタンスを、指定したエラー メッセージステータス使用して初期化します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    status As WebExceptionStatus _
)
Dim message As String
Dim status As WebExceptionStatus

Dim instance As New WebException(message,
 status)
public WebException (
    string message,
    WebExceptionStatus status
)
public:
WebException (
    String^ message, 
    WebExceptionStatus status
)
public WebException (
    String message, 
    WebExceptionStatus status
)
public function WebException (
    message : String, 
    status : WebExceptionStatus
)

パラメータ

message

エラー メッセージテキスト

status

WebExceptionStatus 値の 1 つ

解説解説
使用例使用例

エラー メッセージおよび WebExceptionStatus指定して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. 
     
    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

 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.
   Socket^ httpSocket = gcnew 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 = gcnew IPEndPoint( serverAddress, 80 );
   httpSocket->Connect( endPoint );
   Console::WriteLine( "Connection created successfully" );
   httpSocket->Close();
}
catch ( SocketException^ e ) 
{
   Console::WriteLine( "\nException thrown.\nThe Original Message is: {0}",
 e->Message );
   // Throw the 'WebException' object with a message string and message
 status specific to the situation.
   throw gcnew WebException( "Unable to locate the Server with 'www.contoso.com'
 Uri.", WebExceptionStatus::NameResolutionFailure );
}
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 = (IPAddress)hostEntry.get_AddressList().
        get_Item(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.get_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);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebException コンストラクタ (SerializationInfo, StreamingContext)

指定した SerializationInfo インスタンスStreamingContext インスタンスから、WebException クラス新しインスタンス初期化します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Protected Sub New ( _
    serializationInfo As SerializationInfo, _
    streamingContext As StreamingContext _
)
Dim serializationInfo As SerializationInfo
Dim streamingContext As StreamingContext

Dim instance As New WebException(serializationInfo,
 streamingContext)
protected WebException (
    SerializationInfo serializationInfo,
    StreamingContext streamingContext
)
protected:
WebException (
    SerializationInfo^ serializationInfo, 
    StreamingContext streamingContext
)
protected WebException (
    SerializationInfo serializationInfo, 
    StreamingContext streamingContext
)
protected function WebException (
    serializationInfo : SerializationInfo, 
    streamingContext : StreamingContext
)

パラメータ

serializationInfo

新しい WebException をシリアル化するために必要な情報格納する SerializationInfo。

streamingContext

新しWebException関連付けられているシリアル化ストリーム転送元を格納している StreamingContext。

解説解説

このコンストラクタは、WebException クラスの ISerializable インターフェイス実装ます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebException クラス
WebException メンバ
System.Net 名前空間
ISerializable

WebException コンストラクタ (String, Exception, WebExceptionStatus, WebResponse)

WebException クラス新しインスタンスを、指定したエラー メッセージ入れ子になった例外ステータス、および応答使用して初期化します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    innerException As Exception, _
    status As WebExceptionStatus, _
    response As WebResponse _
)
Dim message As String
Dim innerException As Exception
Dim status As WebExceptionStatus
Dim response As WebResponse

Dim instance As New WebException(message,
 innerException, status, response)
public WebException (
    string message,
    Exception innerException,
    WebExceptionStatus status,
    WebResponse response
)
public:
WebException (
    String^ message, 
    Exception^ innerException, 
    WebExceptionStatus status, 
    WebResponse^ response
)
public WebException (
    String message, 
    Exception innerException, 
    WebExceptionStatus status, 
    WebResponse response
)
public function WebException (
    message : String, 
    innerException : Exception, 
    status : WebExceptionStatus, 
    response : WebResponse
)

パラメータ

message

エラー メッセージテキスト

innerException

入れ子になった例外

status

WebExceptionStatus 値の 1 つ

response

リモート ホストからの応答格納する WebResponse インスタンス

解説解説
使用例使用例

エラー メッセージおよび WebExceptionStatus指定してWebExceptionスローする例を次に示します

 
 ' 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()
      

 // 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.
Encoding^ ASCII = Encoding::ASCII;
String^ requestPage = String::Concat( "GET /nhjj.htm HTTP/1.1\r\nHost: ",
 connectUri, "\r\nConnection: Close\r\n\r\n" );
array<Byte>^ byteGet = ASCII->GetBytes( requestPage );
array<Byte>^ recvBytes = gcnew array<Byte>(256);

// Create an 'IPEndPoint' object.

IPHostEntry^ hostEntry = Dns::Resolve( connectUri );
IPAddress^ serverAddress = hostEntry->AddressList[ 0 ];
IPEndPoint^ endPoint = gcnew IPEndPoint( serverAddress,80 );

// Create a 'Socket' object  for sending data.
Socket^ connectSocket = gcnew 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, (SocketFlags)(0) );

// Receive the information sent by the server.
Int32 bytesReceived = connectSocket->Receive( recvBytes, recvBytes->Length,
 (SocketFlags)(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, (SocketFlags)(0)
 );
   MemoryStream^ memoryStream = gcnew MemoryStream( recvBytes );
   getStream = (System::IO::Stream^)(memoryStream);
   
   // Create a 'WebResponse' object
   WebResponse^ myWebResponse = (WebResponse^)(gcnew HttpConnect( getStream ));
   Exception^ myException = gcnew Exception( "File Not found" );

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

connectSocket->Close();
// Send the data. 
Encoding ascii = Encoding.get_ASCII();
String requestPage = "GET /nhjj.htm HTTP/1.1\r\nHost: " 
    + connectUri + "\r\nConnection: Close\r\n\r\n";
ubyte byteGet[] = ascii.GetBytes(requestPage);
ubyte recvBytes[] = new ubyte[256];
// Create an 'IPEndPoint' object.
IPHostEntry hostEntry = Dns.Resolve(connectUri);
IPAddress serverAddress = (IPAddress)hostEntry.get_AddressList().
    get_Item(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.get_Length(), (SocketFlags)0);
// Receive the information sent by the server.
int bytesReceived = connectSocket.Receive(recvBytes,
    recvBytes.get_Length(), (SocketFlags)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.
        get_Length(), (SocketFlags)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();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebException コンストラクタ

WebException クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

WebException クラス
WebException メンバ
System.Net 名前空間

WebException コンストラクタ (String, Exception)

WebException クラス新しインスタンスを、指定したエラー メッセージ入れ子になった例外使用して初期化します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    innerException As Exception _
)
Dim message As String
Dim innerException As Exception

Dim instance As New WebException(message,
 innerException)
public WebException (
    string message,
    Exception innerException
)
public:
WebException (
    String^ message, 
    Exception^ innerException
)
public WebException (
    String message, 
    Exception innerException
)
public function WebException (
    message : String, 
    innerException : Exception
)

パラメータ

message

エラー メッセージテキスト

innerException

入れ子になった例外

解説解説

WebException インスタンスは、Message プロパティmessage の値に設定し、InnerException プロパティinnerException の値に設定して初期化されますmessagenull 参照 (Visual Basic では Nothing) の場合Message プロパティシステム提供のメッセージ初期化されますInnerException プロパティおよび Response プロパティnull 参照 (Visual Basic では Nothing) に初期化されています。Status プロパティは RequestCanceled に初期化されます

使用例使用例

エラー メッセージおよび入れ子になった例外指定して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. 
     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

 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.
   Socket^ httpSocket = gcnew 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 = gcnew IPEndPoint( serverAddress, 80 );
   httpSocket->Connect( endPoint );
   Console::WriteLine( "Connection created successfully" );
   httpSocket->Close();
}
catch ( SocketException^ e ) 
{
   Console::WriteLine( "\nException thrown.\nThe Original Message is: {0}",
 e->Message );
   //  Throw the 'WebException' object with a message string specific
 to the situation;
   //  and the 'InnerException' that actually led to this exception.
   throw gcnew WebException( "Unable to locate the Server with 'www.contoso.com'
 Uri.", e );
}
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 = (IPAddress)hostEntry.
        get_AddressList().get_Item(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.get_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);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebException コンストラクタ (String)

WebException クラス新しインスタンスを、指定したエラー メッセージ使用して初期化します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

解説解説
使用例使用例

エラー メッセージ指定することによって 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. 
      
    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
 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.
   Socket^ httpSocket = gcnew 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 = gcnew IPEndPoint( serverAddress, 80 );
   httpSocket->Connect( endPoint );
   Console::WriteLine( "Connection created successfully" );
   httpSocket->Close();
}
catch ( SocketException^ e ) 
{
   Console::WriteLine( "\nException thrown.\nThe Original Message is: {0}",
 e->Message );
   
   // Throw the 'WebException' object with a message string specific
 to the situation.
   throw gcnew WebException( "Unable to locate the Server with 'www.contoso.com'
 Uri." );
}
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 = (IPAddress)hostEntry.
        get_AddressList().get_Item(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.get_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.");
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebException コンストラクタ ()

WebException クラス新しインスタンス初期化します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

public WebException ()
public:
WebException ()
public WebException ()
public function WebException ()
解説解説
使用例使用例

既定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

 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.
   Socket^ httpSocket = gcnew 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 = gcnew 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 gcnew 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("http://www.contoso.com");

    IPAddress serverAddress = (IPAddress)hostEntry.get_AddressList()
        .get_Item(0);
    IPEndPoint endPoint = new IPEndPoint(serverAddress, 80);
    httpSocket.Connect(endPoint);
    Console.WriteLine("Connection created successfully");
    httpSocket.Close();
}
catch (SocketException e) {
    String exp = e.get_Message();
    // Throw the WebException with no parameters.
    throw new WebException();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「WebException コンストラクタ」の関連用語

WebException コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebException コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS