HttpListenerException 類別

定義

在處理 HTTP 要求時發生錯誤,所擲回的例外狀況。The exception that is thrown when an error occurs processing an HTTP request.

public ref class HttpListenerException : System::ComponentModel::Win32Exception
[System.Serializable]
public class HttpListenerException : System.ComponentModel.Win32Exception
type HttpListenerException = class
    inherit Win32Exception
Public Class HttpListenerException
Inherits Win32Exception
繼承
屬性

備註

在初始化HttpListener HttpListener期間或在建立或傳送 HTTP 要求的回應期間發生錯誤時, 類別及其相關類別會擲回這個例外狀況。This exception is thrown by the HttpListener class and its associated classes when an error occurs during initialization of the HttpListener or while creating or sending a response to an HTTP request. 例如, 如果HttpListener嘗試登錄已註冊的統一資源識別元 (URI) 前置詞, 就會擲回這個例外狀況。For example, this exception is thrown if the HttpListener attempts to register a Uniform Resource Identifier (URI) prefix that is already registered.

相關秘訣Associated Tips

請確認您未嘗試註冊已被註冊的 URI 前置詞。Make sure you are not attempting to register a URI prefix that is already registered.
如果該 URI 前置詞已被註冊,就會發生這個例外狀況。If the URI prefix is already registered, this exception will occur.

請確認您的 HTTP 要求是有效的。Make sure your HTTP request is valid.
HttpListener 初始化期間,或在建立或傳送 HTTP 要求的回應時發生錯誤,HttpListener 類別及其相關類別就會擲回這個例外狀況。This exception is thrown by the HttpListener class and its associated classes when an error occurs during the initialization of the HttpListener or while creating or sending a response to an HTTP request.

如果您正在使用 HttpListenerPrefixCollection.Add 方法,請確認未曾加入 uriPrefixIf you are using the HttpListenerPrefixCollection.Add method, make sure the uriPrefix has not been already added.
如果另一個 HttpListener 已加入前置詞 uriPrefix,就會擲回這個例外狀況。This exception will be thrown if another HttpListener has already added the prefix uriPrefix.

建構函式

HttpListenerException()

初始化 HttpListenerException 類別的新執行個體。Initializes a new instance of the HttpListenerException class.

HttpListenerException(Int32)

使用指定的錯誤碼,初始化 HttpListenerException 類別的新執行個體。Initializes a new instance of the HttpListenerException class using the specified error code.

HttpListenerException(Int32, String)

使用指定的錯誤碼和訊息,初始化 HttpListenerException 類別的新執行個體。Initializes a new instance of the HttpListenerException class using the specified error code and message.

HttpListenerException(SerializationInfo, StreamingContext)

初始化 HttpListenerException 類別的新執行個體,這個執行個體是來自 SerializationInfoStreamingContext 類別的指定執行個體。Initializes a new instance of the HttpListenerException class from the specified instances of the SerializationInfo and StreamingContext classes.

屬性

Data

取得提供例外狀況之其他使用者定義相關資訊的索引鍵/值組集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(繼承來源 Exception)
ErrorCode

取得值,識別發生的錯誤。Gets a value that identifies the error that occurred.

HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。Gets or sets a link to the help file associated with this exception.

(繼承來源 Exception)
HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。Gets the Exception instance that caused the current exception.

(繼承來源 Exception)
Message

取得描述目前例外狀況的訊息。Gets a message that describes the current exception.

(繼承來源 Exception)
NativeErrorCode

取得與這個例外狀況關聯的 Win32 錯誤碼。Gets the Win32 error code associated with this exception.

(繼承來源 Win32Exception)
Source

取得或設定造成錯誤的應用程式或物件的名稱。Gets or sets the name of the application or the object that causes the error.

(繼承來源 Exception)
StackTrace

取得呼叫堆疊上即時運算框架的字串表示。Gets a string representation of the immediate frames on the call stack.

(繼承來源 Exception)
TargetSite

取得擲回目前例外狀況的方法。Gets the method that throws the current exception.

(繼承來源 Exception)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(繼承來源 Exception)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

以發生這個 SerializationInfo 的檔案名稱和行號,設定 Win32Exception 物件。Sets the SerializationInfo object with the file name and line number at which this Win32Exception occurred.

(繼承來源 Win32Exception)
GetType()

取得目前執行個體的執行階段類型。Gets the runtime type of the current instance.

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回包含 NativeErrorCode,或 HResult,或同時包含兩者的字串。Returns a string that contains the NativeErrorCode, or HResult, or both.

(繼承來源 Win32Exception)

事件

SerializeObjectState

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(繼承來源 Exception)

適用於

另請參閱