NotImplementedException NotImplementedException NotImplementedException NotImplementedException Class

定义

在无法实现请求的方法或操作时引发的异常。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
继承
NotImplementedExceptionNotImplementedExceptionNotImplementedExceptionNotImplementedException
属性

示例

下面的示例将引发此异常不是开发的方法。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

注解

NotImplementedException时特定的方法,get 访问器,将引发异常或 set 访问器作为一种类型的成员存在,但未实现。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() NotImplementedException() NotImplementedException() NotImplementedException()

使用默认属性初始化 NotImplementedException 类的新实例。Initializes a new instance of the NotImplementedException class with default properties.

NotImplementedException(SerializationInfo, StreamingContext) NotImplementedException(SerializationInfo, StreamingContext) NotImplementedException(SerializationInfo, StreamingContext) NotImplementedException(SerializationInfo, StreamingContext)

用序列化数据初始化 NotImplementedException 类的新实例。Initializes a new instance of the NotImplementedException class with serialized data.

NotImplementedException(String) NotImplementedException(String) NotImplementedException(String) NotImplementedException(String)

用指定的错误消息初始化 NotImplementedException 类的新实例。Initializes a new instance of the NotImplementedException class with a specified error message.

NotImplementedException(String, Exception) NotImplementedException(String, Exception) NotImplementedException(String, Exception) 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 Data Data Data

获取提供有关异常的其他用户定义信息的键/值对集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

获取描述当前异常的消息。Gets a message that describes the current exception.

(Inherited from Exception)
Source Source Source Source

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

获取引发当前异常的方法。Gets the method that throws the current exception.

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

当在派生类中重写时,用关于异常的信息设置 SerializationInfoWhen overridden in a derived class, sets the SerializationInfo with information about the exception.

(Inherited from Exception)
GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

创建并返回当前异常的字符串表示形式。Creates and returns a string representation of the current exception.

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

适用于

另请参阅