From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Use try catch for exception handling

Use try catch for exception handling - Visual Basic Tutorial

From the course: Visual Basic Essential Training

Use try catch for exception handling

- [Instructor] Here's our first try catch block. This is the code, the code that could cause the exception. Again, I'm trying to open a file that doesn't exist, so I wrap that in a try block. And then this is an empty catch. Now this will catch any and all exceptions. We're not doing anything in this catch block. Essentially we are ignoring any and all exceptions. This appears to be a nice solution. The application will not crash. But this is not a viable solution because the app is not reporting any problems. We are not capturing any useful information, and unexpected errors might not surface for years. I can tell you from experience that you don't want to go down this road. At the minimum, you should always log information in here so that you can go back and figure out what happened if you're ignoring errors. This is the better way of doing it. Write a catch block. This is a general catch block because we're saying catch this exception. And when we catch that exception, the…

Contents