-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-Language DesignFeature RequestLanguage-C#Resolution-DuplicateThe described behavior is tracked in another issueThe described behavior is tracked in another issue
Description
The normal code:
void M()
{
throw new Exception();
Console.WriteLine();//warning CS0162: Unreachable code detected
}
int M2()
{
if (...) return 42;
throw new Exception();
}But if a method definitely throws exceptions:
void Throw()
{
throw new Exception();
}
void M()
{
Throw();
Console.WriteLine();//no CS0162 warning
}
int M2()
{
if (...) return 42;
Throw();
}//error CS0161: not all code paths return a valueI suggest adding an UnreachableAfterAttribute, and the compiler is aware of it:
[UnreachableAfter]
void Throw()
{
throw new Exception();
}
void M()
{
Throw();
Console.WriteLine();//warning CS0162: Unreachable code detected
}
int M2()
{
if (...) return 42;
Throw();
}//OKReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-Language DesignFeature RequestLanguage-C#Resolution-DuplicateThe described behavior is tracked in another issueThe described behavior is tracked in another issue