Code to get last error in csharp

Q & ACode to get last error in csharp
Admin Staff asked 4 years ago

How to get the last error in csharp?

1 Answers
Admin Staff answered 4 years ago

Below function LastError() will helps you to get last error occur in code and print that error on to the screen :-

private void LastError()
{
 Exception LastError;
 String ShowErrMsg;
 LastError = Server.GetLastError();
 if (LastError!= null)
 {
   ShowErrMsg= LastError.Message;
 }
 else
 {
   ShowErrMsg= “No Errors”;
 }
  Response.Write(“Last Error = ” + ShowErrMsg);
}