Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd like to suggest to you that if you do not know what to do with an exception, do not catch it. Too often, coders catch exceptions and just swallow them whole.</p> <pre><code>catch (Exception ex) { /* I don't know what to do.. *gulp!* */ } </code></pre> <p>Clearly this isn't good, because bad things are happening, and no action is being taken. Only catch exceptions that are actionable!</p> <p>That said, graceful error handling is important. Don't want your app to crash, right? You may find ELMAH useful for web applications, and a global exception handler is pretty easy to set up for WinForms or XAML desktop apps.</p> <p>Putting all that together, you might find this strategy useful: 1. catch specific exceptions that you know might occur (DivideByZeroException, SQLException, etc.) and steer away from the generic catch-all Exception; 2. re-raise the exception after you handle it. e.g.</p> <pre><code>catch (SQLException ex) { /* TODO: Log the error somewhere other than the database... */ throw; // Rethrow while preserving the stack trace. } </code></pre> <p>What can you really do with a SQLException? Did the database connection disappear? Was it a bad query? You probably don't want to add all the handling logic for that, and besides, what if it's something you didn't expect? So just handle the exception if you can, <strong>re-raise</strong> it unless you're certain it's resolved, and gracefully handle it at a <strong>global</strong> level (e.g. Show a message like "Something went wrong, but you might be able to continue working. Detailed info: '[ex.Message]'. Abort or Retry?")</p> <p>HTH!</p> <p>John Saunders, thanks for the correction.</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. 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.
 

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