Can we throw exception from catch block ?

Answers were Sorted based on User's Feedback



Can we throw exception from catch block ?..

Answer / nilesh

Yes. A throw statement can be used in the catch block to re-
throw the exception, which has been caught by the catch
statement. For example:

catch (InvalidCastException e)
{
throw (e); // Rethrowing exception e
}

Is This Answer Correct ?    4 Yes 0 No

Can we throw exception from catch block ?..

Answer / arjun

The exceptions, which we caught inside a catch block, can
re-throw to a higher context by using the keyword throw
inside the catch block. The following program shows how to
do this.

//C#: Exception Handling: Handling all exceptions
using System;
class MyClass
{
public void Method()
{
try
{
int x = 0;
int sum = 100/x;
}
catch(DivideByZeroException e)
{
throw;
}
}
}
class MyClient
{
public static void Main()
{
MyClass mc = new MyClass();
try
{
mc.Method();
}
catch(Exception e)
{
Console.WriteLine("Exception caught here" );
}
Console.WriteLine("LAST STATEMENT");
}
}

Is This Answer Correct ?    3 Yes 0 No

Can we throw exception from catch block ?..

Answer / jignesh panchal

yes

Is This Answer Correct ?    2 Yes 1 No

Can we throw exception from catch block ?..

Answer / vamshi krishna

Try
{
//Implemented code
}
catch(ex)
{
alert(ex.message)
}

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More ASP.NET Interview Questions

What is the significance of ASP.NET routing?

0 Answers   NA,


To bind columns manually which tags do you need to add within the asp:datagrid ?

0 Answers   Siebel,


What are sharepoint pages?

0 Answers  


What is the namespace used to store the information about the user?s locale?

1 Answers   NeoSoft, Siebel,


How does ASP.NET framework maps client side events to Server side events.?

0 Answers  


How do you use css in asp.net?

8 Answers   iBridge,


What are the different modes for the sessionstates in the web.config file?

2 Answers  


What is session and application variable in asp net?

0 Answers  


what are the advantage in asp.net and what are the question ask for interview in vb.net and asp.net

0 Answers   TCS,


What is http post action?

0 Answers  


What is the use of Administration tool in Asp.net 2.0?

2 Answers  


What is difference between ispostback and autopostback in asp net?

0 Answers  


Categories