Can multiple Catch Blocks be executed in .NET applications?

 Posted by vishalneeraj-24503 on 9/6/2014 | Category: .NET Framework Interview questions | Views: 791 | Points: 40
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 

Comments or Responses

Login to post response