title: Handler of AppDomain.CurrentDomain.UnhandledException doesn't get called
body: <p>I'm trying to set up my .net application in such a way, an unhandled exception is always logged somewhere. My understanding is two handlers needs to be set for this, <code>Windows.Forms.Application.ThreadException</code> for UI threads (followed by <code>Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)</code>) and the <code>AppDomain.CurrentDomain.UnhandledException</code> for non-UI threads. I do so in my application's <code>Sub Main()</code>, and the <code>Application.ThreadException</code>-Handler is actually working, but I can't figure out, how to get the <code>AppDomain.CurrentDomain.UnhandledException</code>-Handler to work (or why isn't it working).</p>
  
  <p>My test code is like this:</p>
  
  <pre><code>Private Sub ThreadTask(ByVal StateObj As Object)
          Throw New Exception("Unhandled Exception")
  End Sub
  
  Public Sub CauseException()
      Dim StObj As New ThreadParamsObj
      ThreadPool.QueueUserWorkItem(AddressOf ThreadTask, StObj)
  End Sub
  </code></pre>
  
  <p>If I try it in a minimalistic test application (a Form with a single Button, the <code>AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionHandler</code> is called in <code>Form1_Load</code>) -- it works as expected, a <code>MsgBox</code> is shown etc. But in the "real" application it doesn't work.</p>
  
  <p>What could prevent the event from firing or the handler from handling it?</p>
  
  <p><strong>The answer is:</strong> both <code>System.Data.OracleClient.OracleConnection.Open</code> and <code>Oracle.DataAccess.Client.Open</code> (and maybe other DbConnections) in <strong>.net 3.5</strong>, upgrading to to <strong>.net 4.6.1</strong> fixes the issue.</p>