-
Notifications
You must be signed in to change notification settings - Fork 479
Closed
Labels
BugThe product is not behaving according to its current intended designThe product is not behaving according to its current intended design
Description
Analyzer
Diagnostic ID: CA2200: Rethrow to preserve stack details
Version: [SDK 7.0.100]
Describe the bug
dotnet build or the build action in Visual Studio for Mac didn't show the warning of CA2200.
Steps To Reproduce
- With .NET 7 SDK installed, create a new console app using
dotnet new console -o TestConsoleApp - Replace all content with the following code in Program.cs.
class TestsRethrow
{
static void Main()
{
TestsRethrow testRethrow = new TestsRethrow();
testRethrow.CatchException();
}
void CatchException()
{
try
{
CatchAndRethrowExplicitly();
}
catch (ArithmeticException e)
{
Console.WriteLine("Explicitly specified:{0}{1}",
Environment.NewLine, e.StackTrace);
}
try
{
CatchAndRethrowImplicitly();
}
catch (ArithmeticException e)
{
Console.WriteLine("{0}Implicitly specified:{0}{1}",
Environment.NewLine, e.StackTrace);
}
}
void CatchAndRethrowExplicitly()
{
try
{
ThrowException();
}
catch (ArithmeticException e)
{
// Violates the rule.
throw e;
}
}
void CatchAndRethrowImplicitly()
{
try
{
ThrowException();
}
catch (ArithmeticException)
{
// Satisfies the rule.
throw;
}
}
void ThrowException()
{
throw new ArithmeticException("illegal expression");
}
}
Content of the .csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Expected behavior
Warning should be reported that CA2200 was found.
Actual behavior
No warnings reported.
MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
Restored /Users/james/Projects/Temp/TestConsoleApp/TestConsoleApp.csproj (in 39 ms).
TestConsoleApp -> /Users/james/Projects/Temp/TestConsoleApp/bin/Debug/net7.0/TestConsoleApp.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.64
Additional context
.NET SDK: 7.0.100
OS: MacOS Ventura
Metadata
Metadata
Assignees
Labels
BugThe product is not behaving according to its current intended designThe product is not behaving according to its current intended design