Skip to content

Instantly share code, notes, and snippets.

@michaelviveiros
Created January 28, 2024 01:37
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/25e1235c4e5909748be6fc5d0496ad6f to your computer and use it in GitHub Desktop.
Save michaelviveiros/25e1235c4e5909748be6fc5d0496ad6f to your computer and use it in GitHub Desktop.
Obter o número da linha durante a exceção
try
{
//Seu código
}
catch (Exception ex)
{
//Obtém o rastreamento da exceção com as informações do arquivo de origem.
var st = new StackTrace(ex, true);
//Obtenha o quadro da pilha superior.
var frame = st.GetFrame(0);
//Obtém o número da linha específica do stack frame.
var line = frame.GetFileLineNumber();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment