Click here to Skip to main content
15,918,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If we use try catch block can the customerrorpage be used?
Posted
Updated 21-Oct-10 4:46am
v2
Comments
Dalek Dave 21-Oct-10 10:46am    
Minor Edit for Readability.
shakil0304003 22-Oct-10 0:55am    
Uncleared question.

you can use
try
{
}
catch(Exception e)
{
//it will get all errors in the try block.
}

You can use Global.asax for catch any error in the website & an error page for showing this error.
Example:
void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
        string message = "";

        if (Server.GetLastError() != null)
            message = Server.GetLastError().InnerException.ToString();

        Session["Errormessage"] = message;
        HttpContext.Current.Response.Redirect("~/error.aspx");
    }
 
Share this answer
 
Comments
bgadarsh 22-Oct-10 2:31am    
thank you Shakil and Sandeep it worked finally
shakil0304003 23-Oct-10 4:39am    
Welcome :)
Yes!

In catch block, log the necessary details and then throw the error for .NET to handle based on CustomError tag defined in Web.Config file.
 
Share this answer
 
Hi Sandeep,
My code is like the following

C#
try
                    {
                        //pageload code
                    }
                    catch (SqlException ex)
                    {
                        //mylogfileinforamtion();
                        throw;
                    }

When I'm trying to do this way in the pageload itself the page is being redirected to teh custom error page.

pls help
 
Share this answer
 
v2
I have used like this

MIDL
try
{
}
catch(Exception e)
{
//my exception handling part;
throw;
}


and in web.config file i have placed customerrors mode="off"

and in the global.asax i have placed the above code.

Thank u all
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900