Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 16, 2025

The Visual Basic documentation for the Throw statement was showing an example that conflicts with established .NET best practices. The example demonstrated throwing System.Exception directly:

Throw New System.Exception("An exception has occurred.")

However, the C# documentation correctly advises against this practice, stating: "Don't throw System.Exception, System.SystemException, System.NullReferenceException, or System.IndexOutOfRangeException intentionally from your own source code."

This created inconsistent guidance across the .NET documentation where Visual Basic developers might follow the example and violate best practices.

The fix updates the Visual Basic example to use InvalidOperationException instead:

Throw New InvalidOperationException("The operation is not valid for the current state.")

This change:

  • Aligns with Microsoft's official exception throwing guidelines
  • Resolves the conflict between VB and C# documentation
  • Uses InvalidOperationException, which is explicitly recommended in the best practices documentation
  • Maintains the same educational value for demonstrating the Throw statement syntax

Fixes #35262.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Sep 16, 2025
@Copilot Copilot AI changed the title [WIP] Conflicting recommendations for throwing system.exception Fix conflicting System.Exception recommendation in Visual Basic documentation Sep 16, 2025
@Copilot Copilot AI requested a review from BillWagner September 16, 2025 14:22
Copilot finished work on behalf of BillWagner September 16, 2025 14:22
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review September 16, 2025 17:55
@BillWagner BillWagner requested a review from a team as a code owner September 16, 2025 17:55
@BillWagner BillWagner requested a review from gewarren September 16, 2025 17:55
@BillWagner BillWagner merged commit beab5b1 into main Sep 17, 2025
13 checks passed
@BillWagner BillWagner deleted the copilot/fix-35262 branch September 17, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conflicting recommendations for throwing system.exception
3 participants