NotImplementedException Class


當要求的方法或作業未實作時,所擲回的例外狀況。The exception that is thrown when a requested method or operation is not implemented.

public ref class NotImplementedException : Exception
public ref class NotImplementedException : SystemException
public class NotImplementedException : Exception
public class NotImplementedException : SystemException
public class NotImplementedException : SystemException
public class NotImplementedException : SystemException
type NotImplementedException = class
    inherit Exception
type NotImplementedException = class
    inherit SystemException
Public Class NotImplementedException
Inherits Exception
Public Class NotImplementedException
Inherits SystemException


下列範例會針對尚未開發的方法擲回這個例外狀況。The following example throws this exception for a method that has not been developed.

static void Main(string[] args)
    catch (NotImplementedException notImp)

static void FutureFeature()
    // Not developed yet.
    throw new NotImplementedException();
Sub Main()
    Catch NotImp As NotImplementedException
    End Try

End Sub

Sub FutureFeature()
    ' not developed yet.
    Throw New NotImplementedException()
End Sub


當特定的方法、get 存取子或 set 存取子以類型成員的形式出現,但未執行時,就會擲回 NotImplementedException 例外狀況。The NotImplementedException exception is thrown when a particular method, get accessor, or set accessor is present as a member of a type but is not implemented.

NotImplementedException 使用預設的 Object.Equals 實值,其支援參考相等。NotImplementedException uses the default Object.Equals implementation, which supports reference equality. 如需 NotImplementedException實例的初始值清單,請參閱 NotImplementedException 的函式。For a list of initial values for an instance of NotImplementedException, see the NotImplementedException constructors.

擲回例外狀況Throwing the exception

當該成員仍在開發中,而且只會在生產環境程式碼中執行時,您可以選擇在您自己的類型中,于屬性或方法中擲回 NotImplementedException 例外狀況。You might choose to throw a NotImplementedException exception in properties or methods in your own types when the that member is still in development and will only later be implemented in production code. 換句話說,NotImplementedException 例外狀況應該與「仍在開發中」同義。In other words, a NotImplementedException exception should be synonymous with "still in development."

處理例外狀況Handling the exception

NotImplementedException 例外狀況表示您嘗試叫用的方法或屬性沒有任何執行,因此不提供任何功能。The NotImplementedException exception indicates that the method or property that you are attempting to invoke has no implementation and therefore provides no functionality. 因此,您不應該在 try/catch 區塊中處理這個錯誤。As a result, you should not handle this error in a try/catch block. 相反地,您應該從程式碼中移除成員調用。Instead, you should remove the member invocation from your code. 在程式庫的實際執行版本中實作為成員時,您可以包含對該成員的呼叫。You can include a call to the member when it is implemented in the production version of a library.

在某些情況下,NotImplementedException 例外狀況可能不會用來指出在進入生產階段前程式庫中仍在開發中的功能。In some cases, a NotImplementedException exception may not be used to indicate functionality that is still in development in a pre-production library. 不過,這仍然表示功能無法使用,而且您應該從程式碼中移除成員調用。However, this still indicates that the functionality is unavailable, and you should remove the member invocation from your code.

NotImplementedException 和其他例外狀況類型NotImplementedException and other exception types

.NET Framework 也包含兩個其他的例外狀況類型,NotSupportedExceptionPlatformNotSupportedException,表示類型的特定成員沒有任何執行。The .NET Framework also includes two other exception types, NotSupportedException and PlatformNotSupportedException, that indicate that no implementation exists for a particular member of a type. 在下列情況下,您應該擲回其中一個,而不是 NotImplementedException 例外狀況。You should throw one of these instead of a NotImplementedException exception under the following conditions.

PlatformNotSupportedException 例外狀況PlatformNotSupportedException exception
如果您設計的類型具有一個或多個可在某些平臺上使用的成員,或在某些版本中而不是在其他版本上提供,則可以在不支援功能的平臺上擲回此例外狀況。If you've designed a type with one or more members that are available on some platforms or in some versions but not on others, you can throw this exception on platforms on which the functionality is not supported.

NotSupportedException 例外狀況NotSupportedException exception
如果無法執行介面成員或對抽象基類方法的覆寫,則擲回 NotSupportedException 例外狀況。Throw a NotSupportedException exception if the implementation of an interface member or an override to an abstract base class method is not possible. 例如,Convert.ToInt32(DateTime) 方法會擲回 NotSupportedException 例外狀況,因為日期和時間與32位帶正負號的整數之間沒有有意義的轉換。For example, the Convert.ToInt32(DateTime) method throws a NotSupportedException exception because no meaningful conversion between a date and time and a 32-bit signed integer exists. 在此情況下,必須有方法,因為 Convert 類別會執行 IConvertible 介面。The method must be present in this case because the Convert class implements the IConvertible interface.

如果您已實作為抽象基類,並在其中加入必須由衍生類別覆寫的新成員,您也應該擲回 NotSupportedException 例外狀況。You should also throw a NotSupportedException exception if you've implemented an abstract base class and add a new member to it that must be overridden by derived classes. 在這種情況下,讓成員抽象化會導致無法載入現有的子類別。In that case, making the member abstract causes existing subclasses to fail to load.



使用預設屬性,初始化 NotImplementedException 類別的新執行個體。Initializes a new instance of the NotImplementedException class with default properties.

NotImplementedException(SerializationInfo, StreamingContext)

利用序列化資料,初始化 NotImplementedException 類別的新執行個體。Initializes a new instance of the NotImplementedException class with serialized data.


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

NotImplementedException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況之內部例外狀況的參考,初始化 NotImplementedException 類別的新執行個體。Initializes a new instance of the NotImplementedException class with a specified error message and a reference to the inner exception that is the cause of this exception.



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

(Inherited from Exception)

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

(Inherited from Exception)

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

(Inherited from Exception)

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

(Inherited from Exception)

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

(Inherited from Exception)

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

(Inherited from Exception)

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

(Inherited from Exception)

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

(Inherited from Exception)



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

(Inherited from Object)

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

(Inherited from Exception)

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext)

在衍生類別中覆寫時,使用例外狀況的資訊設定 SerializationInfoWhen overridden in a derived class, sets the SerializationInfo with information about the exception.

(Inherited from Exception)

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

(Inherited from Exception)

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

(Inherited from Object)

建立並傳回目前例外狀況的字串表示。Creates and returns a string representation of the current exception.

(Inherited from Exception)



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

(Inherited from Exception)

Applies to

See also