From the course: Visual Basic Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use try-catch for exception handling

Use try-catch for exception handling - Visual Basic Tutorial

From the course: Visual Basic Essential Training

Start my 1-month free trial

Use try-catch for exception handling

- [Programmer] I'll add some try catch protection in this first event handler by typing in the word try and then pressing the enter key. And then I'll delete this bit of code here, and leave it at the simple try, catch, end try. So, then I'll take this code and move it into the try block. So, what we see here is the try and the end try with a single catch, and this says, run the code in here, and if there's any exceptions doesn't matter what type of exception, run the code in this catch block. In other words, catch any and all exceptions. Now, I'm leaving that blank for the moment. Clicking on this button, you can see that something's happening because this number is incrementing, but we're not aware from the user's perspective that there's this FileNotFoundException happening. The exception is caught in that empty catch block, we're not doing anything in the catch block. Essentially, we are ignoring any and all exceptions.…

Contents