catch multiple exception c#

// if C# v6+, you can use exception filters
catch (Exception ex) when (ex is FormatException || ex is OverflowException)
{
  // do something
}

0
1
Jeff Sours 65 points

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

    throw;
}

0
0
4.29
7

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

    throw;
}

4.29 (7 Votes)
0
3.89
74
Aliciahsteen 105 points

                                                try
            {
                Console.WriteLine("Chose a number: ");
                int usrNo = Convert.ToInt32(Console.ReadLine());
                return usrNo;
            }
            catch (FormatException ex) 
            { 
              ErrorMessagePrintCustomMessage("You pressed a letter"); 
            }
            catch (Exception ex) { ErrorMessageErrorOccured(ex); }

3.89 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
catch multiple exception type c# multiple try with single catch c# c# multiple try catch how to try catch twoo exception c# multi catch exception c# c# catch more than one exception c# catch several exception types c# try catch multiple exceptions c# multi exception try catch with multiple catch c# can i have multiple try catch blocks in c# try catch different exceptions C# multiple exception in one catch block c# c# two try catch 2 try catch in a method C# try catch with multiple exceptions C# catch multiple exceptions c# example c# try catch different exceptions c# one try catch or more multiple catch statements in exception handling in c# c# catch multiple exception type c# api exception with multiple catch catch more than one exception c# try with multiple catch c# c# try catch multiple catches how to generate multiple exceptions C# c sharp multiple try catch c sharp try multiple catch multiple try catch in c# multiple exception in single catch c# c# try with multiple catch c# exception multiple catch how to handle multiple exceptions in c# c# try catch multiple things file contains more than one type exception c# multiple exception c# catching different types exceptions uisng "where" how to hande multiple exception c# dotnet core catch multiple exceptions how to handle bunch of exceptions at once catch 2 exception type c# having to two catch c multi catch c# multi catch try catch multi exception C# new C# multiple exception handling c# catch multiple exceptions in one block if multiple classes throws exception in c# how to use multiple exception in same function in c# csharp function Result how to send multiple errors csharp function how to send multiple errors how to catch all exception in c# c# try catch with multiple exceptions c# catch exception from another method how to avoid multiple catch block for throwing multiple exception c# alternatives to multiple try catch catch multiple exception c asp use multiple catch catch exception c# condition how to catch all exceptions in c# throw different exceptions catch one c# catch mulitple exception types c# catch (Exception exception) when (exception is NetMQException || exception is ArgumentOutOfRangeException || exception is ArgumentNullException) catch 2 exception in same line in c# Two catch handlers cannot have the same type. c# catch multiple methods convert exception to another exception in catch c# c# catch multiple exception many exceptions in one if statement c# catch multiple types of exception in c# Is there way to catch multiple exceptions at once and without code duplication c# 6 how to handle error code list multiple catch block in c# catch list of exceptions c# c# multiple catch c# log multiple exception types c# one try two catch is throwing multiple exceptions in .net bad csharp 2 exceptions in the same catch multiple catch blocks c# dotnet look for multiple exception types c# catch different exception types c# catch 2 exceptions C# catch multiple exception types base and derived try catch more than one exception c# try catch c# multiple exceptions chaining catches C# can i include two exceptions in one catch block in c# c# catch multiple when c# catch multiple types of exception c# double catch exception handling in c# mutlitple catch c# multiple exception catch how to catch all selenium exceptions in python catch different exceptions c# multiple exceptions in catch c# try catch multiple exceptions c# c# multiple exceptions same catch C# multiple catch for multiple exception types catch multiple exceptions c# shared catch bloack c# c# try catch multiple exception c# try multiple catch catch multiple exception c# catching multiple exceptions c# c# multiple catch exceptions c# catch multiple exceptions
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source