Catching an error code status in VB.

Posted on 2010-01-13
Medium Priority
Last Modified: 2013-12-26
Ok, I have some code that looks like
Catch ex As Exception

end try
I need some code to detect which type of exception is thrown. This should look like:
    If ex.StatusCode = SmtpStatusCode.InsufficientStorage Then
    End If
However, ex.statuscode doesn't work for VB. I belive it's just for asp.net. What do I use for vb?
Question by:jumpstart0321
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 42

Accepted Solution

sedgwick earned 1000 total points
ID: 26302853
check http://msdn.microsoft.com/en-us/library/5hsw66as(VS.80).aspx

u can use
 If (TypeOf Err.GetException() Is <THE_EXCEPTION_CLASS>) Then ...
LVL 27

Assisted Solution

planocz earned 1000 total points
ID: 26306995
Here is a quick sample of some of the things you can do with Try/Catch....
You can add alot of catches and even nest them in each catch.
Dim res as Integer
            cmd1.CommandText = gSql
            res = cmd1.ExecuteNonQuery
            If res < 1 Then
                If bFinish = True Then
                    If res = 0 Then Exit Try
                    Throw New System.Exception()
                End If
            End If
        Catch ex As InsufficientMemoryException
            MsgBox("Exception: " & ex.Message & "  " & ex.ToString, MsgBoxStyle.Critical)
            Exit Sub
        Catch ex As AccessViolationException
            MsgBox("Exception: " & ex.Message & "  " & ex.ToString, MsgBoxStyle.Critical)
            Exit Sub
        Catch ex As Exception When res < 1
            ErrorText = "Database update failed. Please try again."
            MsgBox("Exception: " & ErrorText & vbNewLine & "Error #: " & ErrorNumber, MsgBoxStyle.Critical)
            Exit Sub
        Catch ex As Exception
            MsgBox("Exception: " & ex.Message & "  " & ex.ToString, MsgBoxStyle.Critical)
            Exit Sub
        End Try

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 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