Catching Exceptions Without a Variable

You do not always need to specify a variable in the Catch block. This can be the case in which you want to take the same action independently from the exception that occurred. For example, consider the following code:

image

The ex variable is not being used and no specific exceptions are handled. So the preceding code can be rewritten as follows, without the ex variable:

image

Whichever exception occurs, the code shows the specified message. This also works with regard to the re-throw technique. The following code simply ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.