Wednesday, February 19, 2014

Capture line number with exception message in asp.net C#

Sometime, i am writing a long code for implement for some logic in my program and inside my code, multiple try-catch block is exist, then i don't know proper error exception for capture message type. So i have capture all information for generated error.

Add below code in your function:


// 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();

No comments:

Post a Comment

Generate All Database Backup From Sql Server Using Query

DECLARE   @name   VARCHAR ( 50 )   -- database name DECLARE   @path   VARCHAR ( 256 )   -- path for backup files DECLARE   @fileName  ...