Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your requirements are clear - skip files that cannot be read. So what is the problem with the general exception handler? It allows you to perform your task in a manner that is easy, clean, readable, scalable and maintainable.</p> <p>If at any future date you want to handle the multiple possible exceptions differently, you can just add above the general exception the catch for the specific one(s).</p> <p>So you'd rather see the below code? Note, that if you add more code to handle the reading of files, you <strong>must</strong> add any new exceptions to this list. All this to do nothing?</p> <pre><code>try { // find, open, read files } catch(FileNotFoundException) { } catch(AccessViolation) { } catch(...) { } catch(...) { } catch(...) { } catch(...) { } catch(...) { } catch(...) { } </code></pre> <p>Conventions are guidelines and great to try to adhere to to create good code - but do not over-complicate code just to maintain some odd sense of proper etiquette.</p> <p>To me, proper etiquette is to not talk in bathrooms - ever. But when the boss says hello to you in there, you say hello back. So if you don't care to handle multiple exceptions differently, you don't need to catch each.</p> <hr> <p>Edit: So I recommend the following</p> <pre><code>try { // find, open, read files } catch { } // Ignore any and all exceptions </code></pre> <p>The above tells me to not care which exception is thrown. By not specifying an exception, even just System.Exception, I've allowed .NET to default to it. So the below is the same exact code.</p> <pre><code>try { // find, open, read files } catch(Exception) { } // Ignore any and all exceptions </code></pre> <p>Or if you're going to log it at least:</p> <pre><code>try { // find, open, read files } catch(Exception ex) { Logger.Log(ex); } // Log any and all exceptions </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload