In C# how do you find the last error which occurred ?

 Posted by Chvrsri on 1/20/2012 | Category: C# Interview questions | Views: 5975 | Points: 40

This can be done by implementing a method called GetLastError(). Generally this returns a ASPError object stating the error condition that has occurred. This method will work only before the .ASP page sent any content to the Client.

Sample Code

Exception LastErrorOccured;
String ShowErrMessage;
LastErrorOccured = Server.GetLastError();
if (LastErrorOccured != null)
ShowErrMessage = LastErrorOccured.Message;
ShowErrMessage = "No Errors";
Response.Write("Last Error Occured = " + ShowErrMessage);

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Akiii on: 1/23/2012 | Points: 10
This is a useful code.....

Thanks and Regards

Login to post response