title: In C# how can I safely exit a lock with a try catch block inside?
body: <p>Here is an example of an exception happening inside a lock, with a try-catch block.</p>
  
  <pre><code>int zero = 0;
  int j = 10;
  
  lock (sharedResource.SyncRoot)
  {
      try
      {
          j = j / zero;
      }
      catch (DivideByZeroException e)
      {
          // exception caught but lock not released
      }
  }
  </code></pre>
  
  <p>How do I safely release this lock in the catch?</p>