Users Pricing

forum

home / developersection / forums / catch multiple exceptions at once?

Catch multiple Exceptions at once?

Pravesh Singh 2730 13 Jun 2013

It is discouraged to simply catch System.Exception, instead only the "known" Exceptions should be caught.

Now, this sometimes leads to unneccessary repetetive code, for example:

try
{
    WebId = new Guid(queryString["web"]);
}
catch (FormatException)
{
    WebId = Guid.Empty;
}
catch (OverflowException)
{
    WebId = Guid.Empty;
}

I wonder: Is there a way to catch both Exceptions and only call the WebId =

Guid.Empty call once?


Student


1 Answers