Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Can two catch blocks be executed?

Answers were Sorted based on User's Feedback



Can two catch blocks be executed?..

Answer / ravinder singh chauhan

We can use as many catch block with try block but executed
only one at a time...............

Is This Answer Correct ?    31 Yes 3 No

Can two catch blocks be executed?..

Answer / sunny

no,,two catch blocks cnt b executed ..only one will be at
one time,,,,

Is This Answer Correct ?    16 Yes 2 No

Can two catch blocks be executed?..

Answer / 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

Can two catch blocks be executed?..

Answer / kiran

If a finally block contains a try catch block where in
exceptions can occur. In that case exception in the main
try catch block and the exceptions in finally block will
also be thrown.

Is This Answer Correct ?    7 Yes 0 No

Can two catch blocks be executed?..

Answer / awadhesh

For a given set of try catch only one exception block will
get executed. Notice in finally what you are having is a
new set of try catch statements. They are unrelated to the
one above , so it is wrong to say here that two catch
blocks were executed.

Is This Answer Correct ?    8 Yes 1 No

Can two catch blocks be executed?..

Answer / pompana gouda

Close this question.

Correct answer is:

If a finally block contains a try catch block where in
exceptions can occur. In that case exception in the main
try catch block and the exceptions in finally block will
also be thrown.

In the above case not only two catch blocks we can execute
many(N) number of catch blocks.

Is This Answer Correct ?    8 Yes 4 No

Can two catch blocks be executed?..

Answer / khushnood alam

two catch block can be executed but need coresponding try
block
ex
DbTransaction Transaction = Connection.BeginTransaction();
try
{
RemoteDB.ExecuteNonQuery(cmdBfcNew,
Transaction);
if (Convert.ToInt64
(AddBfcNewOutgoingDetails["ID"]) == -1)
{
mID = Convert.ToInt64
(RemoteDB.GetParameterValue(cmdBfcNew, "@ReturnID"));
}
else
{
mID = Convert.ToInt64
(AddBfcNewOutgoingDetails["ID"]);
}
try
{
DbCommand cmdOutgoing =
LocalDB.GetStoredProcCommand
("usp_Outgoing2UpdateAfterUploadingData");
LocalDB.AddInParameter
(cmdOutgoing, "@AwbNo", DbType.String,
AddBfcNewOutgoingDetails["AwbNo"]);
}
catch (Exception Ex)
{
Transaction.Rollback();
Transaction1.Rollback();
return Ex.Message;
}
catch (Exception Ex)
{
Transaction.Rollback
();
return Ex.Message;
}

Is This Answer Correct ?    2 Yes 0 No

Can two catch blocks be executed?..

Answer / kanan

No. Two Catch Blocks for same try can not be executed.

Is This Answer Correct ?    2 Yes 1 No

Can two catch blocks be executed?..

Answer / gyana

NO,we cannot use two catch block.It can't be executed.

Is This Answer Correct ?    3 Yes 3 No

Can two catch blocks be executed?..

Answer / anil chauhan

No.... Its not posible to execute more then one catch block
at one time.

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C Sharp Interview Questions

What is difference between out and ref in c#?

0 Answers  


What is architecture of your poroject? how i c an say?

2 Answers   Eminosoft, HCL, Phoenix Technologies,


Is overriding of a function possible in the same class?

0 Answers  


Why static variables are used?

0 Answers  


What is eager loading in c#?

0 Answers  


what is the purpose of Interfaces?

7 Answers   HCL,


Can we inherit sealed class in c#?

0 Answers  


What are scriptable objects?

0 Answers  


What is a trace and asset? Explain some differences?

0 Answers   Accenture,


How many types of collections are there in c#?

0 Answers  


Can property defined in Interface.

4 Answers   Synechron,


How to assign default value to nullable types? Did nested nullable types are allowed

2 Answers   TCS,


Categories