Alex Rivera | Logout

Show line number in exception handling

Asked 2009-03-27T02:44:12.773
20

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);
}
Edit
Report

1 Answer

48

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).

answered 2009-03-27T02:47:06.213

Your Answer