WebException クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ Public Class WebException Inherits InvalidOperationException Implements ISerializable
[SerializableAttribute] public ref class WebException : public InvalidOperationException, ISerializable

WebException クラスは、インターネットにアクセスするためのプラグ可能プロトコルを実装する WebRequest と WebResponse から派生したクラスによってスローされます。
WebException が WebRequest クラスの派生クラスによってスローされた場合、Response プロパティはアプリケーションにインターネットからの応答を提供します。

System.Exception
System.SystemException
System.InvalidOperationException
System.Net.WebException


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebException コンストラクタ ()
アセンブリ: System (system.dll 内)


既定のコンストラクタは、WebException クラスの新しいインスタンスを初期化します。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. ' 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(); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebException コンストラクタ (String, WebExceptionStatus)
アセンブリ: System (system.dll 内)

Dim message As String Dim status As WebExceptionStatus Dim instance As New WebException(message, status)

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

エラー メッセージおよび 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); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebException コンストラクタ (SerializationInfo, StreamingContext)
アセンブリ: 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 function WebException ( serializationInfo : SerializationInfo, streamingContext : StreamingContext )


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebException コンストラクタ (String, Exception, WebExceptionStatus, WebResponse)
アセンブリ: 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 )

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

エラー メッセージおよび 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();

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebException コンストラクタ

名前 | 説明 |
---|---|
WebException () | WebException クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
WebException (String) | WebException クラスの新しいインスタンスを、指定したエラー メッセージを使用して初期化します。 .NET Compact Framework によってサポートされています。 |
WebException (SerializationInfo, StreamingContext) | 指定した SerializationInfo インスタンスと StreamingContext インスタンスから、WebException クラスの新しいインスタンスを初期化します。 |
WebException (String, Exception) | WebException クラスの新しいインスタンスを、指定したエラー メッセージと入れ子になった例外を使用して初期化します。 .NET Compact Framework によってサポートされています。 |
WebException (String, WebExceptionStatus) | WebException クラスの新しいインスタンスを、指定したエラー メッセージとステータスを使用して初期化します。 .NET Compact Framework によってサポートされています。 |
WebException (String, Exception, WebExceptionStatus, WebResponse) | WebException クラスの新しいインスタンスを、指定したエラー メッセージ、入れ子になった例外、ステータス、および応答を使用して初期化します。 .NET Compact Framework によってサポートされています。 |

WebException コンストラクタ (String, Exception)
アセンブリ: System (system.dll 内)

Dim message As String Dim innerException As Exception Dim instance As New WebException(message, innerException)

WebException インスタンスは、Message プロパティを message の値に設定し、InnerException プロパティを innerException の値に設定して初期化されます。message が null 参照 (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); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebException コンストラクタ (String)
アセンブリ: System (system.dll 内)


Message プロパティを message の値に設定して、WebException インスタンスを初期化します。message が null 参照 (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. 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."); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebException プロパティ

名前 | 説明 | |
---|---|---|
![]() | Data | 例外に関する追加のユーザー定義情報を提供するキー/値ペアのコレクションを取得します。 ( Exception から継承されます。) |
![]() | HelpLink | 例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。 ( Exception から継承されます。) |
![]() | InnerException | 現在の例外を発生させた Exception インスタンスを取得します。 ( Exception から継承されます。) |
![]() | Message | 現在の例外を説明するメッセージを取得します。 ( Exception から継承されます。) |
![]() ![]() | Source | エラーの原因となったアプリケーションまたはオブジェクトの名前を取得または設定します。 ( Exception から継承されます。) |
![]() | StackTrace | 現在の例外がスローされたときにコール スタックにあったフレームの文字列形式を取得します。 ( Exception から継承されます。) |
![]() ![]() | TargetSite | 現在の例外をスローするメソッドを取得します。 ( Exception から継承されます。) |


WebException メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetBaseException | 派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 ( Exception から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetObjectData | オーバーライドされます。 SerializationInfo インスタンスに、WebException をシリアル化するために必要なデータを設定します。 |
![]() | GetType | 現在のインスタンスのランタイム型を取得します。 ( Exception から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の例外の文字列形式を作成して返します。 ( Exception から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Runtime.Serialization.ISerializable.GetObjectData | このインスタンスを、指定した SerializationInfo オブジェクトにシリアル化します。 |

WebException メンバ
プラグ可能プロトコルによるネットワークへのアクセスでエラーが発生した場合にスローされる例外。
WebException データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Data | 例外に関する追加のユーザー定義情報を提供するキー/値ペアのコレクションを取得します。(Exception から継承されます。) |
![]() | HelpLink | 例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。(Exception から継承されます。) |
![]() | InnerException | 現在の例外を発生させた Exception インスタンスを取得します。(Exception から継承されます。) |
![]() | Message | 現在の例外を説明するメッセージを取得します。(Exception から継承されます。) |
![]() ![]() | Source | エラーの原因となったアプリケーションまたはオブジェクトの名前を取得または設定します。(Exception から継承されます。) |
![]() | StackTrace | 現在の例外がスローされたときにコール スタックにあったフレームの文字列形式を取得します。(Exception から継承されます。) |
![]() ![]() | TargetSite | 現在の例外をスローするメソッドを取得します。(Exception から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetBaseException | 派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の主要な原因である Exception を返します。 (Exception から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetObjectData | オーバーライドされます。 SerializationInfo インスタンスに、WebException をシリアル化するために必要なデータを設定します。 |
![]() | GetType | 現在のインスタンスのランタイム型を取得します。 (Exception から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の例外の文字列形式を作成して返します。 (Exception から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Runtime.Serialization.ISerializable.GetObjectData | このインスタンスを、指定した SerializationInfo オブジェクトにシリアル化します。 |

Weblioに収録されているすべての辞書からWebExceptionを検索する場合は、下記のリンクをクリックしてください。

- WebExceptionのページへのリンク