NotImplementedException 類別

定義

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

public ref class NotImplementedException : SystemException
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class NotImplementedException : SystemException
type NotImplementedException = class
    inherit SystemException
Public Class NotImplementedException
Inherits SystemException
繼承
NotImplementedException
屬性

範例

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

static void Main(string[] args)
{
    try
    {
        FutureFeature();
    }
    catch (NotImplementedException notImp)
    {
        Console.WriteLine(notImp.Message);
    }
}

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


End Sub

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

備註

當特定的方法、get 存取子或 set 存取子以類型成員的形式出現, 但未執行時, 就會擲回例外狀況(exception)。NotImplementedExceptionThe 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 也包含兩個其他的例外狀況NotSupportedException類型PlatformNotSupportedException, 以及, 這表示類型的特定成員沒有任何執行存在。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
如果無法執行介面成員或抽象基類方法的覆寫, 就會擲回例外狀況。NotSupportedExceptionThrow 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()

使用預設屬性,初始化 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(String)

使用指定的錯誤訊息,初始化 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.

屬性

Data

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

(繼承來源 Exception)
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)
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)

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

(繼承來源 Exception)
GetType()

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

(繼承來源 Exception)
MemberwiseClone()

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

(繼承來源 Object)
ToString()

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

(繼承來源 Exception)

事件

SerializeObjectState

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

(繼承來源 Exception)

適用於

另請參閱