Here is a simple example:
1 code that causes the exception
Copy Code code as follows:
protected void Button1_Click (object sender, EventArgs e)
{
int a = 5;
int b = 2;
int C;
c = A/(b-2);
}
2) code in the Global.cs
Copy Code code as follows:
protected void Application_Error (object sender, EventArgs e)
{
Get exception information
String strerror = Server.GetLastError (). ToString ();
You can write error messages through log4net to text or libraries, which are written only on the page
Response.Write ("error message:" + strerror + "");
Server.ClearError ();
}
Through the above practice I wrote a demo in the F5 debugging sometimes will output error messages on the page sometimes first in the abnormal place to stop running but then press the F5 error message appears. In IE, FF, chrome are the same problem, it is possible that the browser caching problem. After the launch of their own demo after the view of all normal.