Tag Archives: Try

Basic Error Handling using Try, Catch, End Try using VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 'This is only a basic example code snippet of using the Try,Catch, End Try method for
 'some error handling. Below is just some random code to test with. Works with all versions of Visual Basic .NET

        Dim f As IO.File


            f.Open("D:\fileDoesNotExistFile.txt", IO.FileMode.Open) 'this will cause a file not found error to be thrown.

        Catch exc As Exception
            'This will give a description of the error.
            MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 

        End Try