Error Handle

Posted on 2004-11-17
Last Modified: 2010-04-23
Can someone tell me a good way to handle error with web application? I'm not really sure what to do with errors.

        Catch ex As Exception
        End Try

Question by:Donnie4572
    LVL 96

    Assisted Solution

    by:Bob Learned
    Log errors to a file:

    Exception Management Application Block for .NET

    LVL 19

    Assisted Solution

    I think You'll need to decide for yourself what to do with Errors
    It will depend entirely upon the Type of Error and the severity of the Error in Context to your Application

    For Eg. In case it is an Error in Executing the Query through rhUpdateCommand.ExecuteNonQuery()
    say you are trying to insert a row and the Primary Key value exists So you need to send a message to the User to modify the Primary Key (Say his User ID)

    In all Unimportant (rather UnExpected) cases yuo should Log it in a Log File and show a decent Output to the User.

    LVL 5

    Accepted Solution

    I have mainly 3 approaches to error conditions:

    A) Type 1: they can be ignored. You just log them and continue the process.
    B) Type 2: retry errors. When this kind of error happens you retry the operation until it works.
    B) Type 3: stop errors. When there is a special bad error or any unexpected error I stop the application (you can't handle an unexpected error because ... mmm ... because it's unexpected, thats all.

    Then, I build the sentences like this:

    A) Try
        Catch ex As Exception
             writeToLog("Error happened. Error: " & ex.Message)
        End Try

    B) Dim operationOK as Boolean
        While Not operationOK
                operationOK = true
            Catch ex As Exception
                operationOK = false
            End Try

    C) For stop errors I use to throw an event that shows a message and stops all the app.

    Ask me more if you need it.

    LVL 12

    Author Comment

    Thanks for your help!

    Is it possible to log errors to the event viewer?

    I can't seem to understand what determines the type of the error. Stop, unexpected, retry...
    Should I have a list of error codes?

    if error1 then
    if error2 then
    is error3 then

    If I use error handle with ExecuteNonQuery() and the user does not have permission to update the database (log this error)  then give a message "you do not have permission to update" but if the error is a problem updating the database...say date is in the wrong format... can I give the user a message "change the format of date" then a chance to correct the format and continue working?
    LVL 12

    Author Comment

    Thanks for good answers. Can someone help to implement a simple error handle?

    1.)  UpdateCommand.ExecuteNonQuery() ....this updates SQL database with data from web application

    2.) The SQL database uses windows security to control access to my application that allow read or write depending on the user

    3.) If a user with read permission tries to write to Database I would like to pop up a message "you don't  have permission" (application continues)

    4.) All other errors  (application halts)

    5.) Log all errors I don't care where the log is at.


    LVL 12

    Author Comment

    Ok, so I've researched this and your answer seems to be all there is. It just seems there should be more control.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now