Throwing an Exception in C#
In C#, it is possible to throw an exception programmatically. The ‘throw’ keyword is used for this purpose. The general form of throwing an exception is as follows.
throw exception_obj;
Here I am explain you how throw an exception on the other Error page with the help of Global.asax file
we use try and catch block for exception handling .try
{
//logical part
}
catch (Exception ex)
{
throw (ex);
}
we need Global.asax file for that , so simply create Gloal.asax file for this propose .
Here we need to write code on function Applicaion_Error and redirect the QueryString having Error type message to the page where we want to show the Error Message.
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception ex = Server.GetLastError().GetBaseException();
Response.Redirect("ErrorPage.aspx?error=" + ex.Message);
}
// GetLastError() use to get the current error
Here on the ErrorPage.aspx Page we get the Querystring and show the message ob label
lblErrorMessage.Text= Request.QueryString[0].ToString();
0 comments: