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# multiple exceptions same handler

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 :: check if variable less than in f# 
Csharp :: c# alert message 
Csharp :: function documentation c# exception 
Csharp :: unity c# public all codes 
Csharp :: c# create monochrome bitmap 
Csharp :: "; expected" error c#$ 
Csharp :: Adding number of day remaining to future date from now 
Csharp :: is and as in c# 
Csharp :: c# creat pen 
Csharp :: Destroy(GameObject.Find("Turret_Laser_Hit"), 0.2f); 
Csharp :: querstring fromat asp.net c# 
Csharp :: c# azure get vm get cpu usage 
Csharp :: Razor switch statement 
Csharp :: asp.net mvc hide div from controller 
Csharp :: NetConnectionDispatch 
Csharp :: c# cosmos db add items into container 
Csharp :: .net core not returning the sub list 
Csharp :: unity customize hierarchy window 
Csharp :: unity convert pixels to units 
Csharp :: 110771 
Csharp :: what is the default value for an enum c# 
Csharp :: c# asqueryable select 
Csharp :: web socket background.js example 
Csharp :: c# lambda get all records async 
Csharp :: c# check if list is empty 
Csharp :: asp.net core reverse engineer database 
Csharp :: c# if a new program is started 
Csharp :: tee into file 
Csharp :: blazor OnInitializedAsync Unhandled exception rendering component: Cannot wait on monitors on this runtime. 
Csharp :: spring jar debug level running 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =