we can try multiple try catch in a program but we can use one try catch for single code block
Interviews4 answers
4 Answers
Bidyasagar MishraPosted Jul 8, 2019, 5:18 PM EDT
You can use multiple catch block for one try block.
but there can be only one try block for a single code block.
Pankaj GuptaPosted Mar 12, 2019, 7:50 PM EDT
You can use multiple catch for one try statement and separately you can use as much as you need try catch blocks.
Ivaylo DimitrovPosted Dec 3, 2018, 5:43 AM EST
class emp
{
static void Main(string[] args)
{
Console.WriteLine("Enter 1st and 2nd Number");
try
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int c = a / b;
int d=c+a*b
Console.WriteLine( a, b, c,d);
}
catch(DivideByZeroException ex)
{
LogError(ex);
Console.Write("not divide by zero");
}
catch(InvalidOperationException ex)
{
LogError(ex);
Console.Write("Not a valid number.");
}
catch(FormatException ex)
{
LogError(ex);
Console.Write("Not a valid number. Please try again.");
}
Console.ReadLine();
}
}
M RahmanPosted Apr 18, 2018, 7:22 PM EDT

