Can two catch blocks be executed?

Answer Posted / shadab alam

yes two catch block can be executed .

Sorry for privious Error!whrer two catch block are not
executd but this time it has been executed

Now This is right answer here two


using System;
class a
{
public static void Main()
{
int a=8;
int b=0;
int [] arr=new int[]{1,2};
try
{
Console.WriteLine(a/b);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
Console.WriteLine("Hello");
}
finally
{ try
{
Console.WriteLine(arr[2]);
}
catch(IndexOutOfRangeException d)
{
Console.WriteLine(d.ToString
()+ "hello");
Console.WriteLine("Hello");
}
}
}
}


output will be
----------------
System.DivideByZeroException: Attempted to divide by zero.
at a.Main()
Hello
System.IndexOutOfRangeException: Index was outside the
bounds of the array.
at a.Main()hello
Hello

Is This Answer Correct ?    12 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is c# dictionary a hash table?

477


What does mean before a string in c#?

512


What issues can be faced while delivering code?

1472


What does m mean in decimal c#?

491


What do u mean by delegation of authority?

525






What is the advantage of dependency injection?

495


What are the problem with .NET generics?

550


What is the difference between select and selectmany?

430


Is linkedhashset synchronized?

565


Explain more on CLR

746


What is the difference between dataset and datatable in c#?

542


What is difference between string and stringbuilder in c#?

459


How to exclude a property from xml serialization?

535


Explain the difference between a Private Assembly and a Shared Assembly

511


What is the difference between icomparer and icomparable in c#?

459