Can multiple catch blocks be executed?
Can multiple catch blocks be executed?
In C#, it is possible to have multiple catch blocks within a single try-catch statement. However, only one catch block will be executed, depending on the type of exception that is thrown.
Here's how it works:
Here's an example:
try
{
// Some code that might throw an exception
int result = 10 / 0; // Throws DivideByZeroException
}
catch (DivideByZeroException ex)
{
Console.WriteLine("Caught DivideByZeroExc...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào