Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# catch multiple exceptions

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

two exceptions same catch c#

try
{
// Code
}
catch (Exception ex) when (ex is ArbitraryType1 || ex is ArbitraryType2)
{
  throw;
}
Comment

c# catch multiple exception types

try
{
    /*  Try do something ... */
}
catch (Exception ex) when (ex is InvalidDataException || ex is ArgumentException)
{
    Console.WriteLine("a specific catch");
}
catch (Exception ex)
{
  Console.WriteLine("General catch");
}
Comment

c# catch two exceptions in one block

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

    throw;
}
Comment

c# try catch multiple catches

            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); }
Comment

c# catch multiple exceptions at once

catch (Exception ex)            
{                
    if (ex is FormatException or OverflowException) // Chain as many or xException as you need
    {
        WebId = Guid.Empty;
        return;
    }
    
    throw;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to pause physics in unity c# 
Csharp :: how to play animation with code in unity 
Csharp :: reverse for loop unity 
Csharp :: define a vector c# 
Csharp :: cs entity framework 
Csharp :: Get Index position of an element in a list in c# 
Csharp :: instantiate iqueryable c# 
Csharp :: get connectionstring from web config c# 
Csharp :: c# array map 
Csharp :: c# streamwriter 
Csharp :: how to clear datagridview c# 
Csharp :: c# how many lines in methods 
Csharp :: c# compile into an exe 
Csharp :: c# check if string is path or file 
Csharp :: c# socket listen on port 
Csharp :: unity chat system 
Csharp :: call stored proc c# 
Csharp :: button size xamarin 
Csharp :: how to use distinct in linq query in c# 
Csharp :: unity keycode for f 
Csharp :: destroy game object 
Csharp :: c# list to array 
Csharp :: c# stop process 
Csharp :: c# list tuple 
Csharp :: get all child gameObject of gameObject C# 
Csharp :: mvc get base url 
Csharp :: unity set mouse 
Csharp :: string to biginteger c# 
Csharp :: c# print list 
Csharp :: how to make dictionary c# 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =