> dotnet run -f net9.0
With rethrow:
at RyuJitReproduction.Program.ThrowCatchAndRethrow(Boolean doCatch) in C:\Users\Accretion\source\dotnet\RyuJit\RyuJitReproduction\Program.cs:line 77
at RyuJitReproduction.Program.Main() in C:\Users\Accretion\source\dotnet\RyuJit\RyuJitReproduction\Program.cs:line 94
Offset: 0x54
No rethrow:
at RyuJitReproduction.Program.ThrowCatchAndRethrow(Boolean doCatch) in C:\Users\Accretion\source\dotnet\RyuJit\RyuJitReproduction\Program.cs:line 77
at RyuJitReproduction.Program.Main() in C:\Users\Accretion\source\dotnet\RyuJit\RyuJitReproduction\Program.cs:line 104
Offset: 0x54
Note how the native offsets are equal, and so are the line numbers.
NativeAOT output:
> dotnet publish -f net9.0 /p:PublishAot=true && .\bin\Release\net9.0\win-x64\publish\RyuJitReproduction.exe
With rethrow:
at RyuJitReproduction.Program.ThrowCatchAndRethrow(Boolean) + 0x50
at RyuJitReproduction.Program.Main() + 0x55
Offset: 0x50
No rethrow:
at RyuJitReproduction.Program.ThrowCatchAndRethrow(Boolean) + 0x2d
at RyuJitReproduction.Program.Main() + 0x5e
Offset: 0x2D
Note how different IPs are reported (the IP of the throw is switched to the IP of the rethrow).
Test app:
CoreCLR output:
Note how the native offsets are equal, and so are the line numbers.
NativeAOT output:
Note how different IPs are reported (the IP of the throw is switched to the IP of the rethrow).
See also ThrowStatementDoesNotResetExceptionStackLineOtherMethod, which suggests that this difference is a NativeAOT bug.
This is the reason for the difference: https://github.com/dotnet/runtime/blob/c4792a228ea36792b90f87ddf7fce2477e827822/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs#L66-L73