title: Is there a way to get the last thrown exception outside of a try/catch block?
body: <p><strong>Edit:</strong> </p>
  
  <p>To all answerers and commenters:  Please focus on providing the solution I request rather than offer ways to refactor it.  The code provided below is a very condensed example for the sake of brevity.  I've already stated below that this type of code exists in 20 or 30 places throughout the app and that I am choosing not to move/merge/refactor any of that code if a simpler solution exists.</p>
  
  <p><strong>Original Question:</strong></p>
  
  <p>First, here's brief run-down:  We have an app that was developed by an offshore team.  The purpose of this application is to run nightly maintenance on various database tables.  It is a WinForms app, but it acts more like a console app as all it does is 1) execute a single method in Form1_Load and then 2) call End to shut down the program.</p>
  
  <p>The problem is that the error email notification doesn't work, so I have been charged with the task of fixing it.  Consider this code:</p>
  
  <pre><code>Try
      'This inner Try/Catch is actually code in another method
      Try
          'Run some code here
      Catch ex As Exception
          'Errors are logged silently to text file here
      End Try
  Catch ex As Exception
      'Code to email exception details is here
  End Try
  </code></pre>
  
  <p>The problem is that an exception is thrown and handled in the inner Try/Catch.  Because of this, there's no exception to be handled in the outer Try/Catch, hence why no email notification is being sent.</p>
  
  <p>Someone might say to just add <code>Throw ex</code> in the inner Catch, but keep in mind that there are about 20 or 30 places in the code where exceptions are handled like this.  The decision I am making is to just get it working for now and not undergo that kind of development effort.  Therefore, I seek a way to somehow acquire the last exception thrown by the application.  This way, I can add a Finally block to the outer Try/Catch and do something like this:</p>
  
  <pre><code>Finally
      If Not Application.GetLastException() is Nothing Then
         SendErrorEmail(Application.GetLastException())
      End If
  End Try
  </code></pre>