Skip to content

Remove non-CLS exceptions handlers in LineServicesCallbacks (dead code) - #10874

Open
h3xds1nz wants to merge 1 commit into
dotnet:mainfrom
h3xds1nz:non-cls-exceptions
Open

h3xds1nz wants to merge 1 commit into
dotnet:mainfrom
h3xds1nz:non-cls-exceptions

Conversation

@h3xds1nz

@h3xds1nz h3xds1nz commented May 26, 2025 •

Copy link
Copy Markdown
Member

Description

Removes non-CLS exceptions handlers (general catch handler blocks) in LineServicesCallbacks that are never executed (basically a dead-code). This originates from pre-NetFXv2 / C# 2.0 behaviour before non-CLS exceptions were being wrapped by default as RuntimeWrappedException which derives from Exception and hence you needed a general catch handler.

Nowadays Roslyn emits [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] by default so all non-CLS exceptions are already handled via catch (Exception e) blocks and never fallthrough to the general catch { } handler.

Customer Impact

Smaller assembly size, codegen size and cleaner codebase for developers.

Regression

No.

Testing

Local build.

Risk

Low, those would be caught catched by CS1058 but the warning was suppressed. Reviewers just need to make sure the removed blocks are preceeded by catch (Exception e) to achieve the same effect.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz
h3xds1nz requested a review from a team as a code owner May 26, 2025 09:08
@dotnet-policy-service dotnet-policy-service Bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels May 26, 2025
@codecov

codecov Bot commented May 26, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 2.98881%. Comparing base (57fe8ac) to head (23fbd7c).
⚠️ Report is 278 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main     #10874          +/-   ##
===================================================
- Coverage   13.48885%   2.98881%   -10.50004%     
===================================================
  Files           3317       3319           +2     
  Lines         664749     664746           -3     
  Branches       74643      74675          +32     
===================================================
- Hits           89667      19868       -69799     
- Misses        572488     644697       +72209     
+ Partials        2594        181        -2413     
Flag Coverage Δ
Debug 2.98881% <0.00000%> (-10.50004%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

oysteinkrog pushed a commit to InitialForce/wpf that referenced this pull request Apr 29, 2026
Cherry-pick eb72275 ("Remove warning suppressions") removed CS1058
from PresentationCore.csproj's NoWarn list, but the matching non-CLS
catch removal in ElementUtil.cs (paired with upstream PR dotnet#10876) was
not part of the cherry-picked commit. The dangling empty catch is
unreachable in modern .NET (RuntimeCompatibility wraps non-CLS throws
in RuntimeWrappedException, which derives from Exception and is caught
by the preceding `catch (Exception e)`), so the only consequence of
keeping it was the CS1058 build error.

Mirror the same cleanup upstream applied to LineServicesCallbacks
(PR dotnet#10874), PtsHost (PR dotnet#10875), and the other PTS callbacks
(PR dotnet#10876): delete the empty `catch { }` block.

Behaviour change: a non-CLS throw is now rethrown as
RuntimeWrappedException instead of being silently swallowed (previous
code set remoteException=null which suppressed the rethrow at the
call site). Strictly safer.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant