Programming Tutorials

Throwing an Exception in VB.net

By: Steven Holzner in VB.net Tutorials on 2010-11-17  

You can throw an exception using the Throw statement, and you can also rethrow a caught exception using the Throw statement. Here's an example where I'm explicitly throwing an overflow exception:

Module Module1
    Sub Main()
        Try
            Throw New OverflowException()
        Catch e As Exception
            System.Console.WriteLine(e.Message)
        End Try
    End Sub
End Module
Tip 

In fact, it's even possible to mix structured and unstructured exception handling to some extent-if you're using unstructured exception handling, you can get an exception object with the Err object's GetException method and throw that exception in a Try block.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)