Skip to content

Instantly share code, notes, and snippets.

@michaelviveiros
Last active January 28, 2024 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelviveiros/7e47ea66b6f33a2588e594aea036ba92 to your computer and use it in GitHub Desktop.
Save michaelviveiros/7e47ea66b6f33a2588e594aea036ba92 to your computer and use it in GitHub Desktop.
GetLineNumberDuringErrorException
try
{
//Your Code
}
catch (Exception ex)
{
// Get stack trace for the exception with source file information
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment