Catch multiple exceptions at once

Sometimes it happens that you need to do the same on two different types of Exceptions. I searched but found nothing for VB.NET.

A simple example:

Try '... Catch ex As Net.WebException 'Do something Catch ex As Net.CookieException 'Do the same Catch ex As Exception '... End Try 

I wonder if there is a way to catch both exceptions at once without having to repeat the code.

+9
exception try-catch
source share
1 answer

As seen on Capture multiple exceptions at once? this can be done as follows:

 Catch ex As Exception When TypeOf ex Is FormatException OrElse TypeOf ex Is OverflowException 
+22
source share

All Articles