Answer: It's not possible to execute multiple catch blocks in .NET.If once specific catch block executed then it will go directly to the
finally block.
For Example:-
public static void main(String[] args)
{
int[] input = {2};
String str = "Dot net funda dot com";
try
{
int val1 = 5/args.length;
input[10] = 12;
int val2 = Integer.parseInt(str);
}
catch(ArithmeticException ae)
{
Console.WriteLine("Arithmetic Exception");
}
catch(ArrayIndexOutOfBoundsException abe)
{
Console.WriteLine("ArrayIndex Out Of Bounds Exception");
}
catch(NumberFormatException nfe)
{
Console.WriteLine("Number Format Exception");
}
}
Asked In: Many Interviews |
Alert Moderator