Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't have to catch every possible exception around every line of code.</p> <p>Instead, only catch when you have context and you are prepared to handle and take appropriate action. Otherwise, just let it bubble up.</p> <p>Catching exceptions (especially deep in the stack in common functions where you don't have enough context to handle) can be problematic. It sometimes leads to swallowing and not appropriately handling. Handle exceptions when you have context.</p> <p>For that FileInfo exception it depends how deep in that stack it is. If it's in a library where it can be reached via multiple paths and scenarios, you shouldn't handle, what are you going to do at that point? If that's also the case and it bubble all the way out through a deep stack to a GUI performing an operation where you want to handle it, what are you going to catch? Every possible exception of every code path on it's execution path? And, as code changes, you're going to re-evaluate all paths? In a shallow code path (file info dialog that calls that method) it's an easy call but even then you're not going to handle it differently - you're going to display an error dialog or message in panel. Exception types offer the ability to handle <strong>differently</strong>. In both of those case, you handle exception so I say bah hum bug to that guideline. </p> <p><strong>What is very clear is you should not throw type Exception</strong>. That short circuits the ability to handle differently.</p> <p>Another related post:</p> <p><a href="https://stackoverflow.com/questions/7238402/trying-to-understand-exceptions-in-c-sharp/7238519#7238519">Trying to understand exceptions in C#</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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