title: Get calling method which caused exception in the catch
body: <p>I am handling top level exceptions in the main entry point of a Windows Form. I want to get access to the calling method/assembly which caused the exception in my handler. I have a feeling I will have to use the trace for this but I am not sure where.</p>
  
  <pre><code>Module Program
    Sub Main()
      Try
        AddHandler AppDomain.CurrentDomain.UnhandledException, Function(sender, e) ExceptionHandler.Handle(sender, DirectCast(e.ExceptionObject, Exception))
        AddHandler Application.ThreadException, Function(sender, e) ExceptionHandler.Handle(sender, e.Exception)
        Application.Run(ApplicationBase)
      Catch ex As Exception
        MessageBox.Show("Handled Exception")
      End Try
    End Sub
  End Module
  
  Public Class ApplicationBase
    Public Sub MethodA()
      'Causes an exception
      File.ReadAllLines("")
    End Sub
  End Class
  
  Public Class ExceptionHandler
  
    Public Shared Function Handle(sender As Object, e As Exception)
      Dim t As Type = sender.GetType()
      'Retrieve the calling method here?
      Dim callingMethod = "MethodA"
      Return True
    End Function
  
  End Class
  </code></pre>
  
  <p>The object coming through as the sender is a thread, I was trying to see if this would be the assembly/object type which the call caused an exception.</p>
  
  <p>My question is how do I get the method name/info and at a push the object name/assembly from within the "handle" method, if it is possible?</p>
  
  <p>EDIT:</p>
  
  <p>Although the e.ToString() will present method names - I am looking for access to the a list of methodinfo/the assemblies/the types to which the exception was caused like reflection and then I can get version numbers of .DLL's etc. - I may be dreaming here but it's something I would like to know if it is possible?</p>
  
  <p>EDIT 2:</p>
  
  <p>I tried e.TargetSite which for MethodA() exception returns the method info of File.ReadAllLines() I am looking for the Class method which causes the exception, so the method info would be MethodA - Although this is a lot closer than I would of thought I would get.</p>