-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Description
TypeScript got never
type which allows to define methods that never return.
I propose similar feature for C#.
Methods "returning" noreturn
type must definitely throw or call other noreturn
methods.
They can't have return
statements in their body nor out
parameters. At callsites they should be threated by the compiler similarly to throw
statements.
It will require support from CLR. and that's a good thing as CLR could take advantage of that and optimize generated code around callsites to noreturn
s as it does now with throw
s.
private noreturn LogAndFailFast()
{
s_logger.Log(whatever_required);
Environment.FailFast();
}
static class ThrowHelper
{
public noreturn ThrowInvalidInputException(ObjectType type, long id)
{
throw new InvalidInputException(string.Format(InvalidInputFormatString, type, id));
}
}
Metadata
Metadata
Assignees
Labels
No labels