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

注解

当特定方法、get 访问器或 set 访问器作为类型的成员存在但未实现时, 将引发异常。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 还包括两个其他异常类型: 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
如果接口成员的实现或抽象基类方法的重写不可能, 则引发异常。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. 此方法中必须存在方法, 因为ConvertIConvertible实现接口。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)

适用于

另请参阅