Error Handle

Posted on 2004-11-17
Medium Priority
Last Modified: 2010-04-23
Can someone tell me a good way to handle error with vb.net 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
Bob Learned earned 400 total points
ID: 12611225
Log errors to a file:

Exception Management Application Block for .NET

LVL 19

Assisted Solution

arif_eqbal earned 400 total points
ID: 12611450
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.


Accepted Solution

Ignacio Soler Garcia earned 1200 total points
ID: 12614388
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.

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 12

Author Comment

ID: 12643867
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

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

1.)  UpdateCommand.ExecuteNonQuery() ....this updates SQL database with data from vb.net 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

ID: 12768283
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

807 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