Answers for "multiple try catch c#"

C#
0

c# catch two exceptions in one block

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

    throw;
}
Posted by: Guest on January-23-2020
0

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;
}
Posted by: Guest on July-01-2021

C# Answers by Framework

Browse Popular Code Answers by Language