---
title: "Catch multiple Exceptions at once?"  
description: "Catch multiple Exceptions at once?"  
author: "Pravesh Singh"  
published: 2013-06-13  
updated: 2013-06-13  
canonical: https://www.mindstick.com/forum/1061/catch-multiple-exceptions-at-once  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Catch multiple Exceptions at once?

It is discouraged to simply [catch](https://www.mindstick.com/forum/159341/how-to-use-try-and-catch-in-java-for-exception-handling-and-what-happens-when-an-exception-occurs) System.Exception, instead only the "known" [Exceptions](https://www.mindstick.com/interview/22871/define-predifined-generic-exceptions) should be caught.

[Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now), this sometimes [leads](https://www.mindstick.com/articles/12410/how-can-online-leads-lift-your-roi) to unneccessary repetetive [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii), for example:

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

I [wonder](https://yourviews.mindstick.com/story/2441/wheatgrass-juice-wonder-for-your-health): Is there a way to catch both Exceptions and only call the WebId =

[Guid](https://www.mindstick.com/forum/12585/cast-the-value-returned-from-user-identity-getuserid-to-make-it-a-guid).Empty call once?

## Replies

### Reply by Vijay Shukla

Hello Pravesh Singh!

\

Catch System.Exception and switch on the types

\

```
catch (Exception ex)
{
    if (ex is FormatException || ex is OverflowException)
    {
        WebId = Guid.Empty;
        return;
    }

    throw;
}
```

\


---

Original Source: https://www.mindstick.com/forum/1061/catch-multiple-exceptions-at-once

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
