Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show line number in exception handling

Tags:

How would one display what line number caused the error and is this even possible with the way that .NET compiles its .exes?

If not is there an automated way for Exception.Message to display the sub that crapped out?

try
{
  int x = textbox1.Text;
}
catch(Exception ex)
{
     MessageBox.Show(ex.Message);
}
like image 913
Crash893 Avatar asked Mar 27 '09 02:03

Crash893


People also ask

Which method displays the line number in code where exception happened?

The printStackTrace() method in Java is a tool used to handle exceptions and errors. It is a method of Java's throwable class which prints the throwable along with other details like the line number and class name where the exception occurred.

How do you trace line numbers at which error occurs?

You can find it in the stack trace ( Exception. StackTrace property ), on the last line, but only when your code has been compiled with debugging information included. Otherwise the line number will be unknown.

How can I get line number in stack trace?

The java. lang. StackTraceElement. getLineNumber() method returns the line number of the source line containing the execution point represented by this stack trace element.


1 Answers

Use ex.ToString() to get the full stack trace.

You must compile with debugging symbols (.pdb files), even in release mode, to get the line numbers (this is an option in the project build properties).

like image 197
Steven A. Lowe Avatar answered Oct 09 '22 21:10

Steven A. Lowe