Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove or replace catch blocks that handle SystemException #6271

Closed
rpetrusha opened this issue Jul 2, 2018 · 1 comment
Closed

Remove or replace catch blocks that handle SystemException #6271

rpetrusha opened this issue Jul 2, 2018 · 1 comment
Labels
bulk-changes Indicates issues or PRs that don't apply to a particular topic but to the whole docset doc-enhancement Improve the current content [org][type][category] help wanted Good for community contributors to help [up-for-grabs] sample-code Indicates issues requesting samples

Comments

@rpetrusha
Copy link
Contributor

Remove or replace catch blocks that handle SystemException

See #4870 on the use of Exception in catch blocks.
See #6270** on the use of ApplicationException in catch blocks.

The handling of SystemException is particularly widespread in legacy code (that is, examples written for .NET Framework 1.0, 1.1, and 2.0 that have not been revised subsequently). The problems are:

  • Exception handling with SystemException may be used when no exception handling is needed.
  • Exception handling with SystemException is used instead of handling more specific exceptions. As a general rule, catching SystemException rather than more derived exceptions is not recommended.

To address the issue of incorrect exception handling:

  1. Work in the dotnet/samples repo.
  2. Find the line of code that handles SystemException.
  3. Determine whether exception handling is needed at all. If not, simply delete the try statement and the catch block.
  4. Identify the methods in the try block that are candidates for throwing an exception derived from SystemException, and replace that particular catch statement with one or more catch statements that handle the appropriate exception.
@rpetrusha rpetrusha added doc-enhancement Improve the current content [org][type][category] help wanted Good for community contributors to help [up-for-grabs] P2 bulk-changes Indicates issues or PRs that don't apply to a particular topic but to the whole docset labels Jul 2, 2018
@rpetrusha rpetrusha added this to the Backlog milestone Jul 2, 2018
@rpetrusha
Copy link
Contributor Author

The following are C# code examples that handle SystemException. In almost all cases, there is a parallel Visual Basic example in the corresponding snippets/visualbasic directory, and in some cases, there is a parallel C++ example in the corresponding snippets/cpp directory.

  • snippets\csharp\VS_Snippets_CLR\Process_GetProcessesByName2_2\CS\process_getprocessesbyname2_2.cs
  • snippets\csharp\VS_Snippets_CLR\Process_StandardError\CS\source.cs
  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.UIPermission\CS\uipermission.cs
  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.UrlIdentityPermission\CS\urlidentity.cs
  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.ZoneIdentityPermission\CS\zoneidentity.cs
  • snippets\csharp\VS_Snippets_Winforms\ContainerExmpl\CS\librarycontainer.cs

Mackiovello added a commit to Mackiovello/samples that referenced this issue Oct 13, 2018
Projects for .NET Community Contributors automation moved this from Maintenance to Done Oct 23, 2018
rpetrusha pushed a commit to dotnet/samples that referenced this issue Oct 23, 2018
* Remove unecessary try..catch for getprocessbyname

For dotnet/docs#6271

* Remove unecessary try..catch for Process_StandardError

* Remove unecessary try..catch for uipermission

* Remove unecessary try..catch from urlidentity

* Remove unecessary try..catch for zoneidentity

* Remove unecessary try..catch for librarycontainer

* Remove unecessary try..catch for urlidentity for c++ and VB

* Remove unecessary try..catch from uipermission on VB

* Remove unecessary try..catch from process_standarderror on c++ and VB

* Remove unecessary try..catch for process_getprocessbyname with c++ and VB

* Handle exception properly for GetProcessByName on C#

* Handle InvalidOperationException

* Remove UnionDemo

* Handle exceptions properly in LibraryContainer

* Handle exception for GetProcessByName on VB

* Remove outdated C++ examples for GetProcessByName and LibraryContainer
@rpetrusha rpetrusha added this to Candidates in Vendor work items Mar 11, 2019
@rpetrusha rpetrusha removed this from Candidates in Vendor work items Mar 11, 2019
@mairaw mairaw removed this from the Backlog milestone Oct 16, 2019
@BillWagner BillWagner added sample-code Indicates issues requesting samples and removed 📁 Repo - samples labels Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bulk-changes Indicates issues or PRs that don't apply to a particular topic but to the whole docset doc-enhancement Improve the current content [org][type][category] help wanted Good for community contributors to help [up-for-grabs] sample-code Indicates issues requesting samples
Projects
No open projects
Development

No branches or pull requests

3 participants