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

What is Named parameter in C#?

552


What is cosole application?

574


What is int32 in c#?

501


What is dbcontext c#?

484


What is the difference between the debug class and trace class? Documentation looks the same.

509






How do you convert byte array to hexadecimal string, and vice versa?

537


Explain partial class in c#?

497


What are data types with examples?

512


Can we inherit a private class in c#?

464


What is the concept of strong names?

537


Will the following code compile?

557


Explain the functionalities of satellite assembly?

551


What is an assembly in .net?

572


What are custom attributes in c#?

499


i want o/p 011242110 in c# code.

1636