4 July 2011

Get the Function name,Line number,Columnnumber of the Error in C#

//Get the Function name,Line number,Columnnumber of the Error in C#
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
CustomError();
}
catch (Exception ex)
{
StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
MessageBox.Show("Function Name:"+trace.GetFrame(0).GetMethod().Name);
MessageBox.Show("Line Number: " + trace.GetFrame(0).GetFileLineNumber());
MessageBox.Show("Column: " + trace.GetFrame(0).GetFileColumnNumber());
}
}

private void CustomError()
{
throw new Exception("An error has happened");
}
}
}

No comments:

Post a Comment

Comments Welcome

Consistency level in Azure cosmos db

 Consistency level in Azure cosmos db Azure Cosmos DB offers five well-defined consistency levels to provide developers with the flexibility...