Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: static NotImplementedException throw helper. #111113

Open
MaxMahem opened this issue Jan 6, 2025 · 3 comments
Open

[API Proposal]: static NotImplementedException throw helper. #111113

MaxMahem opened this issue Jan 6, 2025 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime untriaged New issue has not been triaged by the area owner

Comments

@MaxMahem
Copy link

MaxMahem commented Jan 6, 2025

Background and motivation

With the CallerMemberName attribute, an informative static throw helper could be generated for NotImplementedException similar to some throw helpers on other exception types.

API Proposal

public class NotImplementedException : SystemException
{
+   [DoesNotReturn]
+   public static void Throw([CallerMemberName] string? unimplementedMemberName = null)
}

API Usage

public class MyClass : IMyInterface
{
    public void SomeUnimplementedMethod() => NotImplementedException.Throw();
}

Alternative Designs

Alternatively/additionally, an overload that returns a TReturn could be used so that the method could be used fluently:

public TReturn Throw<TReturn>([CallerMemberName] string? unimplementedMemberName = null)

Risks

N/A.

@MaxMahem MaxMahem added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 6, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 6, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 6, 2025
@huoyaoyuan huoyaoyuan added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 6, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@huoyaoyuan
Copy link
Member

This is not as useful as ArgumentException.Throw* helpers, because:

  • Argument exception helpers are wrapping testing logic together with throwing, but NotImplementedExeption is meant to be thrown unconditionally.
  • Other throw helpers can separate the actual throwing statement from hot path of a method, but throwing NotImplementedExeption is meant to be the only statement of a method.
  • Method name can be easily retrieved in stack trace. It's not as useful as parameter name, which can be multiple in a method.

@julealgon
Copy link

I'm against this one on the basis that NotImplementedException should only be used at development time, like // TODO comments, and are supposed to be removed before code is finalized.

I would be ok with a static guard for NotSupportedException however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants