Vantage_SWE

Hello!

I like to find a way to get the line numbers when I trap my UnhandledExceptions (that I set up in the ApplicationEvents.vb file).

During debugging mode (under the IDE.e) I can get this from the StackTrace method but this seems to not be available during run time outside the IDE.

Is there any way to achieve this For instance, if I run my app without trapping the unhandled exceptions .NET Framework shows it own dialogue box with trace info including a line number! Where does the MS people get this from

Best regards/
Magnus


Re: .NET Base Class Library Get line number at unhandled exception during runtime (no debugger)

Ryan Lamansky

File and Line information is only available if PDB files exist for the DLLs and EXEs used; which is the default behavior for Debug builds. You can enable PDB files for Release builds, but by default, optimization is used which means line numbers won't be accurate.

Without the PDB, you can still get the exact method name that triggered the exception, which with good file management strategies durinng development, is as good as a file name and nearly as good as a line number.

The StackTrace property on Exceptions includes the function call heiarchy and possible line numbers, depending on PDB availability.

-Ryan / Kardax





Re: .NET Base Class Library Get line number at unhandled exception during runtime (no debugger)

Peter Ritchie

That information is in the PDB.




Re: .NET Base Class Library Get line number at unhandled exception during runtime (no debugger)

Vantage_SWE

Thanks for the answer :)

But I feel a bit lazy; could you (or someone) give me a hint how to see the exact method that triggered the exception in VB or C#

I already have the event handler set up:

Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException

' Some code...
' How can I see the exact method that triggered this handle

End Sub

Best regards/
Magnus