I\'m working on my first ever assignment in ASP.NET. It\'s a website and I work in Visual Studio.
What I can\'t figure out is how to get a detailed error message to
Change your catch
to be catch (Exception ex)
and you can then use Response.Write(ex.Message)
Ideally, you would have different catches for different exception types. This is a bucket approach to catching all exceptions.
Change your catch to catch (SqlException ex) and catch (Exception ex)
catch (SqlException ex)
{
StringBuilder errorMessages = new StringBuilder();
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #......" + i.ToString() + Environment.NewLine +
"Message:....." + ex.Errors[i].Message + Environment.NewLine +
"LineNumber:.." + ex.Errors[i].LineNumber + Environment.NewLine);
}
WriteToLog(FileLog, "SQL Error message: " + errorMessages.ToString() + Environment.NewLine);
WriteToLog(FileLog, "Process has been finished with errors." + Environment.NewLine);
}
catch (Exception ex)
{
WriteToLog(FileLog, "Error message: " + ex.Message + Environment.NewLine);
WriteToLog(FileLog, "Error stack trace: " + ex.StackTrace + Environment.NewLine);
WriteToLog(FileLog, "Process has been finished with errors." + Environment.NewLine);