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 Exception #4870

Open
jinek opened this issue Apr 4, 2018 · 10 comments
Open

Remove or replace catch blocks that handle Exception #4870

jinek opened this issue Apr 4, 2018 · 10 comments
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] mvp-docs-sprint For tracking purposes (used for the MVP summit docs sprint hack). Pri3
Milestone

Comments

@jinek
Copy link

jinek commented Apr 4, 2018

There are a lot of examples demonstrating the use of "catch(Exception)" or "catch{}" that leads application to unexpected behavior.
Literally such catch block says "whatever happened lets do one thing". In most cases it does not make sense.

For example, on this page there is code catch (Exception ex) { Console.WriteLine("Exception caught in CreateTestMessage1(): {0}", ex.ToString() );
In case of any issues with application itself or environment that finished by Exception (NullReferenceException, OutOfMemoryException etc) we just swallow that exception and put some information in to console. First of all any unhandled exception in console application will be written to console by itself. Second, should the caller of this method be notified about something happened? Again, in most cases yes, because mostly code that follows this method assumes this method success. If the task was just "try to send email" then we should put appropriate exception types (SmtpFailedRecipientException, SmtpException etc), because other exceptions do not mean email was not sent, situation when exception was thrown after email was sent possible too. In common other exceptions not stated in documentation can be not related to email sending at all.

Statement from c# Programming Guide:
Do not catch an exception unless you can handle it and leave the application in a known state. If you catch System.Exception, rethrow it using the throw keyword at the end of the catch block.
More information here: MSDN

I think in most cases try/catch blocks can be just removed from examples. Sometimes they can be replaced/improved by exact exception type catching and sometimes by rethrowing.
In very rare case catch{} makes sense in context of application lifetime considering.

We have fixed such several examples, but there are much more of them (example) (especially in code related to UWP).
I'd like to assign to it, but anyway I want to discuss it as new examples will be added, may be it makes sense to create documentation tests, for example.

@mairaw , asking you, please, kindly review this issue as you already had a deal with it

@mairaw mairaw added doc-enhancement Improve the current content [org][type][category] bulk-changes Indicates issues or PRs that don't apply to a particular topic but to the whole docset help wanted Good for community contributors to help [up-for-grabs] labels Apr 9, 2018
@mairaw mairaw added this to the Backlog milestone Apr 9, 2018
@rpetrusha
Copy link
Contributor

rpetrusha commented Apr 10, 2018

Thanks for opening this issue, @jinek. This is a problem throughout the documentation set, so I've added it to the .NET Community Contributors project.. So if anyone would like to work on this, please let us know.
The handling of Exception 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 Exception is used when no exception handling is needed. It evidently was part of a samples boilerplate, and so sometimes even appears when calling methods that don't throw an exception.
  • Exception handling with Exception is used instead of handling more specific exceptions. As a general rule, catching Exception rather than more derived exceptions is not recommended.
  • There are also cases of catching ApplicationException and SystemException. Neither practice is recommended. (I'll open separate issues for these.)

@jinek
Copy link
Author

jinek commented Apr 10, 2018

I would like to work on it

@rpetrusha
Copy link
Contributor

Thank you so much for your offer to help with addressing exception handling in the doc set, @jinek! I'll respond by tomorrow with a detailed plan for reviewing the examples that will help to get you started.

@rpetrusha
Copy link
Contributor

rpetrusha commented Jul 2, 2018

To address the issue of incorrect exception handling:

  1. Work in the dotnet/samples repo.
  2. Find the line of code that handles Exception.
  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, and replace that particular catch statement with one or more catch statements that handle the appropriate exception.

@rpetrusha
Copy link
Contributor

The following are some of the samples that catch Exception. These are all C# examples. In most cases, there is a parallel Visual Basic example in the corresponding snippets\visualbasic directory, and there is sometimes an example in the corresponding snippets\cpp directory.

  • snippets\csharp\VS_Snippets_CLR\AccessControl.FileSystemAuditRule\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\aescryptoservprovider\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\aesmanaged\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\aessample\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\AppCompat.JIT64\cs\SO1.cs

  • snippets\csharp\VS_Snippets_CLR\AccessControl.FileSystemAuditRule\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\aescryptoservprovider\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\aesmanaged\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\aessample\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\AppCompat.JIT64\cs\SO1.cs

  • snippets\csharp\VS_Snippets_CLR\AppDomain_CreateComInstanceFrom\CS\createcominstancefrom.cs

  • snippets\csharp\VS_Snippets_CLR\AppDomain_DefineDynamicAssembly\CS\definedynamicassembly.cs

  • snippets\csharp\VS_Snippets_CLR\AppDomain_LoadRaw\CS\loadraw.cs

  • snippets\csharp\VS_Snippets_CLR\AppDomain_UnhandledException\CS\unhandledexception.cs

  • snippets\csharp\VS_Snippets_CLR\AssemblyInstaller\CS\assemblyinstaller.cs

  • snippets\csharp\VS_Snippets_CLR\AssemblyResolve\CS\assemblyresolve.cs

  • snippets\csharp\VS_Snippets_CLR\AssemblyResolve\CS\assemblyresolve.cs

  • snippets\csharp\VS_Snippets_CLR\assemblyresolverecursive\cs\example.cs

  • snippets\csharp\VS_Snippets_CLR\CatchException\CS\catchexception.cs

  • snippets\csharp\VS_Snippets_CLR\CatchException\CS\catchexception2.cs

  • snippets\csharp\VS_Snippets_CLR\CatchException\CS\catchexception3.cs

  • snippets\csharp\VS_Snippets_CLR\conceptual.basicio.textfiles\cs\source3.cs

  • snippets\csharp\VS_Snippets_CLR\conceptual.basicio.textfiles\cs\source6.cs

  • snippets\csharp\VS_Snippets_CLR\conceptual.tap_patterns\cs\patterns1.cs { tcs.SetException(exc); }

  • snippets\csharp\VS_Snippets_CLR\CounterCreationDataCollection_AddRange\CS\countercreationdatacollection_addrange.cs

  • snippets\csharp\VS_Snippets_CLR\CounterCreationDataCollection_Contains\CS\countercreationdatacollection_contains.cs

  • snippets\csharp\VS_Snippets_CLR\CounterCreationDataCollection_CounterCreationData\CS\countercreationdatacollection_ctor.cs

  • snippets\csharp\VS_Snippets_CLR\CounterCreationDataCollection_CounterCreationData\CS\countercreationdatacollection_ctor_countercreationdata.cs

  • snippets\csharp\VS_Snippets_CLR\CounterCreationDataCollection_CounterCreationDataCollection\CS\countercreationdatacollection_ctor.cs

  • snippets\csharp\VS_Snippets_CLR\CounterCreationDataCollection_CounterCreationDataCollection\CS\countercreationdatacollection_ctor_countercreationdatacollection.cs

  • snippets\csharp\VS_Snippets_CLR\CounterCreationDataCollection_Insert_IndexOf\CS\countercreationdatacollection_insert_indexof.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.3DES.Create.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.3DES.Create.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.3DES.Createstring.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.3DES.Createstring.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.3DESCSP.CreateEncryptor.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.3DESCSP.CreateEncryptor.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.DES.Create.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.DES.Create.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.DES.Createstring.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.DES.Createstring.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.DESCSP.CreateEncryptor.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.DESCSP.CreateEncryptor.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.PasswordDerivedbytes\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.RC2.Create.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.RC2.Create.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.RC2.Createstring.File\CS\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.RC2.Createstring.Memory\CS\memoryexample.cs

  • snippets\csharp\VS_Snippets_CLR\cryptography.rijndael.create.file\cs\fileexample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.RsaCryptoServiceProvider.CspKeyContainerInfo\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML-EncryptedData - EncryptedType\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML-EncryptedData - EncryptedType\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.DataReference\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.DataReference\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.EncryptedData\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.EncryptedData\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.EncryptedKey\cs\example.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.EncryptedKey\cs\example.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.EncryptionProperty\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.EncryptionProperty\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.MainXMLEncDecryptDataOOP\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.MainXMLEncDecryptDataOOP\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncImbedKey\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncImbedKey\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMapKey\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMapKey\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMapKeyX509\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMapKeyX509\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMinimalDecrypt\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMinimalDecrypt\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMinimalDecryptData\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Cryptography.XML.XMLEncMinimalDecryptData\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\dg_exceptionDesign\cs\example1.cs

  • snippets\csharp\VS_Snippets_CLR\dg_exceptionDesign\cs\example1.cs

  • snippets\csharp\VS_Snippets_CLR\directoryinfomoveto\CS\directoryinfomoveto.cs

  • snippets\csharp\VS_Snippets_CLR\DirInfo Class Example\CS\dirinfo class example.cs

  • snippets\csharp\VS_Snippets_CLR\DirInfo Create\CS\dirinfo create.cs

  • snippets\csharp\VS_Snippets_CLR\DirInfo Ctor\CS\dirinfo ctor.cs

  • snippets\csharp\VS_Snippets_CLR\DirInfo Delete1\CS\dirinfo delete1.cs

  • snippets\csharp\VS_Snippets_CLR\DirInfo GetDirs2\CS\dirinfo getdirs2.cs

  • snippets\csharp\VS_Snippets_CLR\DirInfo GetFileSysInfos2\CS\dirinfo getfilesysinfos2.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_CreateDir\CS\dir_createdir.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_GetCreation\CS\dir_getcreation.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_GetCurDir\CS\dir_getcurdir.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_GetDirs2\CS\dir_getdirs2.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_GetDirs2\CS\dir_getdirs3.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_GetFiles2\CS\dir_getfiles2.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_GetLastAccess\CS\dir_getlastaccess.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_GetLastWrite\CS\dir_getlastwrite.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_SetLastAccess\CS\dir_setlastaccess.cs

  • snippets\csharp\VS_Snippets_CLR\Dir_SetLastWrite\CS\dir_setlastwrite.cs

  • snippets\csharp\VS_Snippets_CLR\DPAPI-HowTO\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\EntryWrittenEventArgs_ctor1\CS\entrywritteneventargs_ctor1.cs

  • snippets\csharp\VS_Snippets_CLR\EntryWrittenEventArgs_ctor2\CS\entrywritteneventargs_ctor2.cs

  • snippets\csharp\VS_Snippets_CLR\EventLogEntryType_6\CS\eventlogentrytype_6.cs

  • snippets\csharp\VS_Snippets_CLR\EventLogEntry_CopyTo\CS\eventlogentry_copyto.cs

  • snippets\csharp\VS_Snippets_CLR\EventLogEntry_Item\CS\eventlogentry_item.cs

  • snippets\csharp\VS_Snippets_CLR\exception.data\CS\data.cs{

  • snippets\csharp\VS_Snippets_CLR\exception.data\CS\data.cs{

  • snippets\csharp\VS_Snippets_CLR\FieldBuilder_SetCustomAttributes\CS\fieldbuilder_setcustomattributes.cs

  • snippets\csharp\VS_Snippets_CLR\File Create1\CS\file create1.cs

  • snippets\csharp\VS_Snippets_CLR\File GetLastAccess\CS\file getlastaccess.cs

  • snippets\csharp\VS_Snippets_CLR\File GetLastWrite\CS\file getlastwrite.cs

  • snippets\csharp\VS_Snippets_CLR\File Move\CS\file move.cs

  • snippets\csharp\VS_Snippets_CLR\File Open2\CS\file open2.cs

  • snippets\csharp\VS_Snippets_CLR\File Open3\CS\file open3.cs

  • snippets\csharp\VS_Snippets_CLR\File SetLastAccess\CS\file setlastaccess.cs

  • snippets\csharp\VS_Snippets_CLR\File SetLastWrite\CS\file setlastwrite.cs

  • snippets\csharp\VS_Snippets_CLR\fileinfoopen\CS\fileinfoopen.cs

  • snippets\csharp\VS_Snippets_CLR\FInfo Class\CS\finfo class.cs

  • snippets\csharp\VS_Snippets_CLR\FInfo Ctor\CS\finfo ctor.cs

  • snippets\csharp\VS_Snippets_CLR\FInfo Delete\CS\finfo delete.cs

  • snippets\csharp\VS_Snippets_CLR\FInfo Open2\CS\finfo open2.cs

  • snippets\csharp\VS_Snippets_CLR\FSizeSort\CS\fsizesort.cs

  • snippets\csharp\VS_Snippets_CLR\HowToDecryptXMLElementAsymmetric\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToDecryptXMLElementAsymmetric\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToDecryptXMLElementX509\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEmitCodeInPartialTrust\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEmitCodeInPartialTrust\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEmitCodeInPartialTrust\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEncryptXMLElementAsymmetric\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEncryptXMLElementAsymmetric\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEncryptXMLElementAsymmetric\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEncryptXMLElementSymmetric\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToEncryptXMLElementX509\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToSignXMLDocumentRSA\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\HowToVerifyXMLDocumentRSA\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.DiretoryInfo.GetAccessControl-SetAccessControl\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.File.Encrypt-Decrypt\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.File.GetAccessControl-SetAccessControl\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.File.Replace\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.FileInfo.Encrypt-Decrypt\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.FileInfo.GetAccessControl-SetAccessControl\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.FileInfo.Replace\CS\sample.cs

  • snippets\csharp\VS_Snippets_CLR\IO.FileStream.ctor1\CS\example.cs

  • snippets\csharp\VS_Snippets_CLR\IO.FileStream.ctor2\CS\example.cs

  • snippets\csharp\VS_Snippets_CLR\Microsoft.Win32.SafeHandles.SafeFileHandle\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Microsoft.Win32.SafeHandles.SafeFileHandle.ctor\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Microsoft.Win32.SafeHandles.SafeWaitHandle\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Microsoft.Win32.SafeHandles.SafeWaitHandle-ctor\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR\Module.MethodResolve\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR\Module.MethodResolve\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR\openfilewindowsstore\cs\mainpage.xaml.cs

  • snippets\csharp\VS_Snippets_CLR\ParseMethod\cs\Default.aspx.cs

  • snippets\csharp\VS_Snippets_CLR\ParseMethod\cs\Default.aspx.cs

  • snippets\csharp\VS_Snippets_CLR\ParseMethod\cs\Default.aspx.cs

  • snippets\csharp\VS_Snippets_CLR\ParseMethod\cs\Default.aspx.cs

  • snippets\csharp\VS_Snippets_CLR\ParseMethod\cs\Default.aspx.cs

  • snippets\csharp\VS_Snippets_CLR\ParseMethod\cs\Default.aspx.cs

  • snippets\csharp\VS_Snippets_CLR\pathcombine\CS\pathcombine.cs

  • snippets\csharp\VS_Snippets_CLR\PerformanceCounterInstaller\CS\performancecounterinstaller.cs

  • snippets\csharp\VS_Snippets_CLR\Process.Start_instance\CS\processstart.cs

  • snippets\csharp\VS_Snippets_CLR\process_asyncstreams\CS\net_async.cs

  • snippets\csharp\VS_Snippets_CLR\process_asyncstreams\CS\nmake_async.cs

  • snippets\csharp\VS_Snippets_CLR\ReadTextFile\CS\readtextfile.cs

  • snippets\csharp\VS_Snippets_CLR\RegistrySecurity101\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\RegistrySecurity101\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\rfc28981\CS\rfc28981.cs

  • snippets\csharp\VS_Snippets_CLR\RijndaelManaged Example\CS\class1.cs

  • snippets\csharp\VS_Snippets_CLR\Runtime.InteropServices.PreserveSigAttribute\cs\example.cs

  • snippets\csharp\VS_Snippets_CLR\ServiceController\CS\servicecontroller.cs

  • snippets\csharp\VS_Snippets_CLR\StackFrameSample1\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\StackFrameSample1\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\StackFrameSample1\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\StackFrameSample1\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\StackFrameSample1\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\StackFrameSample1\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\stackframesample2\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\stackframesample2\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\stackframesample2\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\StackTraceSample1\CS\stacktracesample1.cs

  • snippets\csharp\VS_Snippets_CLR\StackTraceSample1\CS\stacktracesample1.cs

  • snippets\csharp\VS_Snippets_CLR\StackTraceSample2\CS\stacktracesample2.cs

  • snippets\csharp\VS_Snippets_CLR\StackTraceSample3\CS\stacktracesample3.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader Ctor1\CS\strmreader ctor1.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader Ctor2\CS\strmreader ctor2.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader CurrentEncoding\CS\strmreader currentencoding.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader Peek\CS\strmreader peek.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader Read1\CS\strmreader read1.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader Read2\CS\strmreader read2.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader ReadLine\CS\strmreader readline.cs

  • snippets\csharp\VS_Snippets_CLR\StrmReader ReadToEnd\CS\strmreader readtoend.cs

  • snippets\csharp\VS_Snippets_CLR\sys.glob.carib.register\CS\persist.cs

  • snippets\csharp\VS_Snippets_CLR\sys.glob.carib.unregister\CS\unregister.cs

  • snippets\csharp\VS_Snippets_CLR\T.CompareTo\CS\cat.cs

  • snippets\csharp\VS_Snippets_CLR\tripledescryptoserviceprovider\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\TypeLoadException_Constructor3\CS\typeloadexception_constructor3.cs

  • snippets\csharp\VS_Snippets_CLR\Type_FindMembers\CS\type_findmembers.cs

  • snippets\csharp\VS_Snippets_CLR\Type_GetInterface\CS\type_getinterface.cs

  • snippets\csharp\VS_Snippets_CLR\Type_IsSerializable\CS\type_isserializable.cs

  • snippets\csharp\VS_Snippets_CLR\whatsnew.casting\cs\program.cs

  • snippets\csharp\VS_Snippets_CLR\WindowsIdentity Impersonation\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR\windowsidentity impersonation2\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR_Classic\classic Debug.Fail Example\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_Classic\classic Debug.Fail1 Example\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_Classic\classic PrincipalPermissionAttribute Example\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_Classic\classic Trace.Fail Example\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_Classic\classic Trace.Fail1 Example\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.appdomain.load\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.CodeDom.CodeDirectives\CS\codedirective.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.CodeDOM.Generics.1\CS\codedomgenerics.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.collections.concurrent.iproducerconsumercollection\cs\iprodcon.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.collections.concurrent.iproducerconsumercollection\cs\iprodcon.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.console.setout\cs\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.PerformanceCounterCategory.OtherMembers\CS\perfCounterCatDelete.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.PerformanceCounterCategory.OtherMembers\CS\perfCounterCatDelete.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.PerformanceCounterCategoryType\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.PerformanceCounterCategoryType\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.PerformanceCounterCategoryType\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.PerformanceCounterCategoryType\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.Process.EnableExited\CS\processexitedevent.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.Process.Id\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.TraceSource\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.TraceSource\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.TraceSource\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Diagnostics.TraceSource2\CS\program.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.Directory\CS\class2.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.Directory\CS\class4.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.Directory\CS\class5.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.Directory\CS\class6.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.io.directory.delete\cs\class1.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.io.directory.delete\cs\class2.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.FileSystemInfo_touch\cs\touch.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.IsolatedStorage.GetStore\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.IsolatedStorage.IsolatedStorage\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.IsolatedStorage.IsolatedStorage\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.IsolatedStorage.IsolatedStorage\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.IO.IsolatedStorage.IsolatedStorage\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.io.windowsruntimestreamextensionsex\cs\mainpage.xaml.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Linq.Queryable\CS\queryable.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.reflection.emit.typebuilder.makegenerictype\cs\remarks.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.runtime.interopservices.marshal.getactiveobject\cs\marshal.getactiveobject.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.AsymmetricAlgorithm\CS\customcrypto.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.AsymmetricAlgorithm\CS\customcrypto.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.CryptoAPITransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.CryptoAPITransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter\CS\rsaencoder.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.RSAOAEPKeyExchangeDeformatter\CS\rsaencoder.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.Keyreference\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.Keyreference\cs\sample.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.XmlDsigBase64Transform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.XmlDsigC14NTransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.XmlDsigXPathTransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.XmlDsigXPathTransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Cryptography.Xml.XmlDsigXsltTransform\CS\members.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.EnvironmentPermission\CS\environmentpermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.EnvironmentPermission\CS\environmentpermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.EnvironmentPermission\CS\environmentpermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\fileiopermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\fileiopermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\fileiopermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\fileiopermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\fileiopermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\fileiopermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\fileiopermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermission\CS\remarks.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermissionAttribute\CS\fileiopermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.FileIOPermissionAttribute\CS\fileiopermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.GacIdentityPermission\CS\gacidentitypermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.GacIdentityPermission\CS\gacidentitypermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.GacIdentityPermission\CS\gacidentitypermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.GacIdentityPermission\CS\gacidentitypermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.GacIdentityPermission\CS\gacidentitypermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.GacIdentityPermission\CS\gacidentitypermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.GacIdentityPermissionAttribute\CS\gacidentitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.HostProtectionAttribute.1.1\CS\hostprotectionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.HostProtectionAttribute.1.1\CS\hostprotectionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.HostProtectionAttribute.1.1\CS\hostprotectionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.KeyContainerPermission\CS\keycontainerpermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.KeyContainerPermission\CS\keycontainerpermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.KeyContainerPermission\CS\keycontainerpermission.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.PermissionSetAttribute\CS\permissionsetattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.PermissionSetAttribute\CS\permissionsetattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.PermissionSetAttribute\CS\permissionsetattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.SecurityPermissionAttribute\CS\securitypermissionattribute.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.StrongNameIdentityPermission\CS\strongnameidentity.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.StrongNameIdentityPermission\CS\strongnameidentity.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Permissions.StrongNameIdentityPermission\CS\strongnameidentity.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.PermissionSet\CS\permissionset.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Policy.Evidence\CS\evidence_evidence.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Policy.GacMembershipCondition\CS\gacmembershipcondition.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Policy.GacMembershipCondition\CS\gacmembershipcondition.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Policy.GacMembershipCondition\CS\gacmembershipcondition.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Policy.GacMembershipCondition\CS\gacmembershipcondition.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Policy.GacMembershipCondition\CS\gacmembershipcondition.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.policy.policylevel\CS\policylevel.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.Principal.WindowsBuiltInRole Example\CS\source.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Security.SecurityException\CS\form1.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.Single\CS\singlesample.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.threading.spinlock\cs\spinlock.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.threading.spinlock\cs\spinlock.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.type.gettypefromclsid\cs\gettypefromclsid_ex2.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.type.gettypefromclsid\cs\gettypefromclsid_ex4.cs

  • snippets\csharp\VS_Snippets_CLR_System\system.typedreference\cs\source.cs

@rpetrusha rpetrusha changed the title Unnecessary catch block is used in a lot of examples not related to exception handling subject Remove or replace **catch** blocks that handle **Exception** Jul 2, 2018
@rpetrusha rpetrusha changed the title Remove or replace **catch** blocks that handle **Exception** Remove or replace catch blocks that handle Exception Jul 2, 2018
@eashi
Copy link

eashi commented Oct 23, 2019

Is there a reason why this issue is still open when the changes have already been made and merged? What am I missing?

@dotnet-bot dotnet-bot added the won't fix Issues that were closed as part of automated backlog grooming label Jan 25, 2021
@dotnet-bot
Copy link
Contributor

This issue has been closed as part of the issue backlog grooming process outlined in #22351.

That automated process may have closed some issues that should be addressed. If you think this is one of them, reopen it with a comment explaining why. Tag the @dotnet/docs team for visibility.

@jinek
Copy link
Author

jinek commented Jan 25, 2021

Is there a reason why this issue is still open when the changes have already been made and merged? What am I missing?

There were fixed only few. Thousands of them remain same issue.

@sharwell sharwell removed the won't fix Issues that were closed as part of automated backlog grooming label Jan 26, 2021
@sharwell sharwell reopened this Jan 26, 2021
@IEvangelist IEvangelist added the mvp-docs-sprint For tracking purposes (used for the MVP summit docs sprint hack). label Apr 4, 2023
@Kissaki
Copy link
Contributor

Kissaki commented Jun 6, 2024

Is this actionable? How would the relevant places be identified?

@jinek
Copy link
Author

jinek commented Jun 8, 2024

Is this actionable? How would the relevant places be identified?

Either analysis rule https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1031 can be checked or using regular expression. chatGPT proposed this:

catch\s*\(\s*(System\.(Exception|SystemException|ApplicationException)|Exception)\s*\)\s*\{(?:(?!\bthrow\b).)*\}

It will probably give some false-positive lines tho.

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] mvp-docs-sprint For tracking purposes (used for the MVP summit docs sprint hack). Pri3
Projects
None yet
Development

No branches or pull requests

9 participants