שתף באמצעות


Error Codes & Messages In VB.NET

Question

Sunday, January 27, 2008 9:01 AM

Hello everyone....

This is Abhijit Annaldas, I am a VB.NET developer. I want a compiled list of all error codes and messages in vb.net.

I want to display a user friendly message instead of the following method...

Try

..........

Catch ex as Exception

MsgBox(ex.message.tostring())

End Try

 

If i get this i would do it as...

For Eg: In case of duplication of a primary key field value in the Database.

Try

..........

Catch ex as Exception

If errcode=<somecode> Then

Msgbox("Duplicate entry not allowed")

End If

End Try

If you get such compiled list of all error codes and messages in vb.net pls mail me to :

abhi_thatsme@hotmail.com 

or

abhi_mailmeat@yahoo.co.in

 

Please reply if you have a solution.

 

Thanks in advance

Abhijit

All replies (1)

Wednesday, January 30, 2008 9:53 AM ✅Answered

 abhijit annaldas wrote:

I want a compiled list of all error codes and messages in vb.net.

I want to display a user friendly message

If you get such compiled list of all error codes and messages in vb.net pls mail me to :

 

 

Hi Abhijit,

 

Please check this document to get Error Messages list.

http://msdn2.microsoft.com/en-us/library/bed4w0y2.aspx

 

Visual Studio Error Messages

      Lists errors that can occur within the integrated development environment (IDE).

Visual Studio Macros Error Messages

      Lists errors that can occur while working with macros.

 

Project Error Messages

      Lists errors that can occur while working with Visual Basic and Visual C# projects.

Error Messages (Visual Basic)

      Lists errors that can occur while running applications created using Visual Basic.

 

To display user-friendly message, here are two suggestions:

 

1. Using the try-catch statement containing more catch clauses, which specify handlers for different exceptions.

    http://msdn2.microsoft.com/en-us/library/0yd65esw.aspx

Code Snippet

Public Class Form1

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try

            Dim s As String = Nothing

            ProcessString(s)

            ' Most specific:

        Catch ex As ArgumentNullException

            MessageBox.Show(ex.Message & " First exception caught.")

            ' Least specific:

        Catch ex As Exception

            MessageBox.Show(ex.Message & " Second exception caught.")

        End Try

    End Sub

 

    Public Sub ProcessString(ByVal s As String)

        If s Is Nothing Then

            Throw New ArgumentNullException()

        End If

    End Sub

 

End Class

 

 

2. Use custom error message in multiple If-Else statement.

Code Snippet

 

        If errcode = somecode Then

 

            MsgBox("Duplicate entry not allowed")

 

        ElseIf con.State = ConnectionState.Closed Then

 

            MsgBox("Database connection has been closed.")

 

        End If

 

I hope that can help you.

 

Regards,

Martin