[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting error line nuber in ASP.Net - C#

Posted on 2009-02-19
2
Medium Priority
?
258 Views
Last Modified: 2013-12-17
Hello,

How do I get the exact line number that has resulted in an exception?
Regards,
MI
0
Comment
Question by:vj_mi
  • 2
2 Comments
 
LVL 39

Expert Comment

by:abel
ID: 23680343
You don't. You can use the .Stacktrace to find it, and the .Source to know the right file. There are tools that fill this gap, though.
0
 
LVL 39

Accepted Solution

by:
abel earned 1500 total points
ID: 23680360
Sorry, my mistake, I answered too quickly. Here's a sample code in C# that does what you want:

try
{
    // Some code that can cause an exception.
 
    throw new Exception("An error has happened");
}
catch (Exception ex)
{
    System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
 
    MessageBox.Show(trace.GetFrame(0).GetMethod().Name);
    MessageBox.Show("Line: " + trace.GetFrame(0).GetFileLineNumber());
    MessageBox.Show("Column: " + trace.GetFrame(0).GetFileColumnNumber());
}

Open in new window

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question