Error Handle

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.

Try
            SqlConnection1.Open()
            rhUpdateCommand.ExecuteNonQuery()
        Catch ex As Exception
            Response.Write(ex.ToString())
        Finally
            SqlConnection1.Close()
        End Try

Thanks,
Donnie
LVL 12
Donnie4572Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Log errors to a file:

Exception Management Application Block for .NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/emab-rm.asp

Bob
0
arif_eqbalCommented:
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.

 
0
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
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
         doSomething()
    Catch ex As Exception
         writeToLog("Error happened. Error: " & ex.Message)
    End Try

B) Dim operationOK as Boolean
    While Not operationOK
        Try
            doSomething()
            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.

SoMoS
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Donnie4572Author Commented:
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

Example:
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?
0
Donnie4572Author Commented:
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.

Donnie



0
Donnie4572Author Commented:
Ok, so I've researched this and your answer seems to be all there is. It just seems there should be more control.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.