Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6861303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:31:04+00:00 2026-05-27T02:31:04+00:00

I am using VS2005 C#, and I have an application which has a few

  • 0

I am using VS2005 C#, and I have an application which has a few functions like list, edit database, import and export of data.

However, I have no clue of catching and handling errors. Below is a sample screenshot of an error met when the column of a file imported does not match with the database, and stops the application from running and points straight to my backend code:
enter image description here

Preiovusly I am using Netbeans and it clearer to me in Netbeans because they always specify each error with an error code, so I was able to assign a webpage for each individual error code.

May I know how can I identify these errors and how can I handle them? Is it possible to assign a webpage redirection when an error is met?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:31:04+00:00Added an answer on May 27, 2026 at 2:31 am

    There are three ways to handle exceptions in ASP.NET:

                1. All the exceptions will catch  page level.
                2. All the exceptions will catch entire site level.
                3. All the exceptions will catch by using "web.config" file
    

    Examples:

    1.Exception Handling at page level.

           public void Page_Error(object obj, EventArgs ergs)
            {
    
                Exception objErr = Server.GetLastError().GetBaseException();
                string err = "Error Caught in Application_Error event " +    
                             System.Environment.NewLine + "Error in: " + Request.Url.ToString() +
                             System.Environment.NewLine + "Error Occured Time:" + DateTime.Now +
                             System.Environment.NewLine + "Error Message:" + objErr.Message.ToString() +
                             System.Environment.NewLine + "Stack Trace:" + objErr.StackTrace.ToString();
                Response.Write(err);
                Server.ClearError();
                Response.Redirect("~/customError.aspx");
            }
    

    2.Exception Handling at website level.

        protected void Application_Error(object sender, EventArgs e)
            {
                Exception objErr = Server.GetLastError().GetBaseException();
                TraceExceptions objExceptionInsert = new  TraceExceptions();
                objExceptionInsert.StackTrace = objErr.StackTrace;
                objExceptionInsert.Exception = objErr.Message;
                objExceptionInsert.Page = Request.Url.AbsolutePath;
               //Inserting exception into the database
                int exceptioncode = Utilities.TraceException(objExceptionInsert);
                Server.ClearError();
               //Redirecting to common exception page
                string url = "~/Common/Exceptions.aspx?ExceptionCode=" + exceptioncode;
                Response.Redirect(url);
    
            }
    

    3.Exception Handling at website level by using web.config.

    The customErrors element of the web.config file is the last line of defense against an unhandled error. If you have other error handlers in place, like the Application_Error of Page_Error subs, these will get called first. Provided they don’t do a Response.Redirect or a Server.ClearError, you should be brought to the page(s) defined in the web.config. In the web.config file, you can handle specific error codes (500, 404, etc), or you can use one page to handle all errors. This is a major difference between this method and the others (although you can emulate this by doing various Response.Redirects using the other methods). Open up your web.config file. The customErrors section uses this format:

    <customErrors defaultRedirect="url" mode="On|Off|RemoteOnly">
       <error statusCode="statuscode" redirect="url"/>
    </customErrors>
    

    Here is some important information about the “mode” attribute:
    “On” specifies that custom errors are enabled. If no defaultRedirect is specified, users see a generic error.

    “Off” specifies that custom errors are disabled. This allows display of detailed errors.

    “RemoteOnly” specifies that custom errors are shown only to remote clients, and ASP.NET errors are shown to the local host. This is the default.

    By default, the section looks like this when you create a Web application.

    <customErrors mode="RemoteOnly" 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2005 ASP.NET 2.0. I have a web application which uses Active
I have developed a window application in VS2005 using C#. I need to integrate
I have a Windows 7 machine on which I am using VS2005. .Net 2.0
I have a VS2005 web application I am using the MySQL active record templates
All I have built a windows form application using VS 2005 Standard edition which
I am using C# VS2005 and SQL Server 2005. I have an Excel import
I have developed an application which uses MS Access database (provider = microsoft jet)
I have a web application on VS2005 using C#. Whenever my webpage does not
I have a very nice MVC Beta application developed using VS2008 on a win2008
I am using VS2008 to develop a WinForms 2.0 application. I have read about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.