Can two catch blocks be executed?
Answers were Sorted based on User's Feedback
Answer / gyana
NO,we cannot use two catch block.It can't be executed.
Is This Answer Correct ? | 2 Yes | 3 No |
Answer / guest
yes. not only 2 catch blocks but 'N' number of catch blocks
associated with respective try block can be executed.
Is This Answer Correct ? | 1 Yes | 7 No |
Yes Yes
Two catch block can be executed at one time.
The example is given bellow .
using System;
class ab
{
public static void Main()
{
int []arr=new int[2]{2,3};
int a=9;
int b=0;
try
{
int r=a/b;
}
catch(DivideByZeroException d)
{
Console.WriteLine(d.ToString());
}
catch(Exception aa)
{
Console.WriteLine(aa.ToString());
}
finally
{
Console.WriteLine(arr[3]);
}
}
}
output will be
-------------
System.DivideByZeroException: Attempted to divide by zero.
at ab.Main()
Unhandled Exception: System.IndexOutOfRangeException: Index
was outside the boun
ds of the array.
at ab.Main()
Is This Answer Correct ? | 6 Yes | 16 No |
What are the access allowed for compilation units(namespace),class and structs and what are its default access?
What is literal in c#?
Is lazy thread safe c#?
What is the default value of boolean variable?
Name the two classes are required for implementing a windows service?
What is a multicast delegate in c#?
Can I get the name of a type at runtime?
What is attribute c#?
How will you deploy the dll file in gac?
What is gui in c#?
How big is int16?
Explain nullable types in c#?