Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch multiple exceptions at the same time

There is sometimes that one want to do the same on two different types of Exception. I searched, but I didn't find anything for VB.NET.

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 needed to repeat code.

like image 798
SysDragon Avatar asked Feb 15 '13 06:02

SysDragon


1 Answers

As seen on Catch multiple exceptions at once? it can be done this way:

Catch ex As Exception When TypeOf ex Is FormatException OrElse TypeOf ex Is OverflowException
like image 61
SysDragon Avatar answered Sep 20 '22 18:09

SysDragon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!