My classes that implements an interface, I've got to throw an exception if the class doesn't support values from parent class (done by setting the get property to false/true), so why should I use NotSupportedException
, but not NotImplementedException
?
When should I use NotImplementedException
then? learn.microsoft.com say that it's always better to use NotSupportedException, is it true?
I've found sth like that: https://blog.excastle.com/2004/10/15/notimplementedexception-vs-notsupportedexception/, but it was written in 2004, I think many changed after that. Also, it is written in quite complicated way.
The NotImplementedException exception indicates that the method or property that you are attempting to invoke has no implementation and therefore provides no functionality. As a result, you should not handle this error in a try/catch block. Instead, you should remove the member invocation from your code.
NotSupportedException indicates that no implementation exists for an invoked method or property.
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. You should throw one of these instead of a NotImplementedException exception under the following conditions.
The NotSupportedException exception indicates that a method has no implementation and that you should not call it. You should not handle the exception.
The NotImplementedException is a way of declaring that a particular method of an interface or base class is simply not implemented in your type. This is the exception form of the E_NOTIMPL error code.
Throw New NotImplementedException() End Sub Remarks. 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 uses the default Object.Equals implementation, which supports
"Not Implemented" implies that it could be implemented it in the future. "Not Supported" makes no such implication as to whether you may implement it or if it even can be implemented.
NotImplementedException
is generally used during development as a way to flag to yourself (or Testers, or any other developers) that some aspect hasn't been implemented yet but it is intended to be implemented. You wouldn't normally include this exception in a formal release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With