forum

Home / DeveloperSection / Forums / Catch multiple Exceptions at once?

Catch multiple Exceptions at once?

Pravesh Singh246413-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?


Updated on 13-Jun-2013

Can you answer this question?


Answer

1 Answers

Liked By