Represents errors that occur during execution when a requested method or operation is not implemented.
The NotImplementedException
class is used to indicate that a
requested operation has not been implemented. This exception is typically
thrown by methods or properties that have not yet been fully developed or
are not intended to be supported. It's a common placeholder during the
development process to signal incomplete functionality.
When NotImplementedException
is thrown, it signals a problem
in the program's logic or design, indicating that the caller attempted to
access functionality that is not yet available.
Constructor | Description |
---|---|
NotImplementedException()
|
Initializes a new instance of the NotImplementedException class with a default message.
|
NotImplementedException(string message)
|
Initializes a new instance of the NotImplementedException class with a specified message.
|
NotImplementedException(string message, Exception innerException)
|
Initializes a new instance of the NotImplementedException class with a specified message and a reference to the inner exception that is the cause of this exception.
|
Here's a simple example demonstrating how NotImplementedException
might be used in a class that is still under development:
public class Shape
{
public virtual double GetArea()
{
throw new NotImplementedException("The GetArea method is not implemented for the base Shape class.");
}
public virtual double GetPerimeter()
{
throw new NotImplementedException("The GetPerimeter method is not implemented for the base Shape class.");
}
}
public class Circle : Shape
{
public double Radius { get; set; }
public override double GetArea()
{
// Area calculation for a circle
return Math.PI * Radius * Radius;
}
// GetPerimeter is not yet implemented for Circle
// public override double GetPerimeter() { ... }
}
// --- In another part of the application ---
try
{
Shape myShape = new Circle { Radius = 5 };
// Calling GetPerimeter on a shape where it's not implemented will throw the exception
double perimeter = myShape.GetPerimeter();
Console.WriteLine($"Perimeter: {perimeter}");
}
catch (NotImplementedException ex)
{
Console.WriteLine($"Error: {ex.Message}");
// Handle the situation, perhaps log the error or inform the user.
}