Hi @Shervan360 , Welcome to Microsoft Q&A,
There is no difference in your two sample codes.
Check out the official explanation to find out:
If you follow the base type of the corresponding exception in the catch. Then it can enter the corresponding catch block for processing when an exception is thrown.
When an exception occurs, the catch clauses are checked from top to bottom in the order specified. For any exception thrown at most one catch block is executed., you can omit the declaration of the exception variable and specify only the exception type in the catch clause. No catch clause of the specified exception type matches any exception, and if one exists, it must be the last catch clause.
For example, provide multiple catch clauses:
try
{
var result = await ProcessAsync(-3, 4, cancellationToken);
Console.WriteLine($"Processing succeeded: {result}");
}
catch (ArgumentException e)
{
Console.WriteLine($"Processing failed: {e.Message}");
}
catch (OperationCanceledException)
{
Console.WriteLine("Processing is cancelled.");
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.