Programming Tutorials

Throwing a Custom Exception in VB.net

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

You can customize the exceptions you throw by creating a new exception object based on the ApplicationException object. Here's an example where I'm creating a new ApplicationException object with the text "This is a new exception", and then throwing and catching that exception:

Module Module1
    Sub Main()
        Try
            Throw New ApplicationException("This is a new exception")
        Catch e As Exception
            System.Console.WriteLine(e.Message)
        End Try
    End Sub
End Module

Here's what you see when you run this console application:

This is a new exception





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)