Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Catching an error code status in VB.

Posted on 2010-01-13
2
Medium Priority
?
305 Views
Last Modified: 2013-12-26
Ok, I have some code that looks like
try
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?
0
Comment
Question by:jumpstart0321
2 Comments
 
LVL 42

Accepted Solution

by:
Meir Rivkin 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 ...
0
 
LVL 27

Assisted Solution

by:planocz
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
        Try
            cmd1.CommandText = gSql
            res = cmd1.ExecuteNonQuery
            If res < 1 Then
                If bFinish = True Then
                    If res = 0 Then Exit Try
                Else
                    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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

564 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