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 difference between view state and session state?

0 Answers  


WHAT IS OBJECT POOLING

2 Answers   Fidelity,


if i have placed the button control with the OnClick event like <asp:Button ID="mybutton" runat="server" Text="Insert" onclick="mybutton_Click" /> and some other controls(buttons, textboxes) in .aspx page. When i run the page, the button displays in the page source of the browser like <input type="submit" name="mybutton" value="Insert" id="mybutton" /> here, it does not display the onclick event, then how the page calls the button click on the server side, how the server side identify which button cause the submit, and how this page moves to the server side.

1 Answers  


How would you get asp.net running in apache web servers?

0 Answers  


Define the term Web Garden?

0 Answers   Sans Pareil IT Services,






What is the difference between managed and unmanaged code? *******

2 Answers   Patni,


1. What is Connection Pooling…? 2. Maintaining Sessions in ASP.NET 3. ASP.NET page lifecycle. 4. Can we store objects in sessions. 5. What is AJAX..? 6. Serialization/Deserialization. Why we use serialization and Deserialization…? 7. What are Arrays and Arraylist..? 8. Difference between Authentication and Authorization…? 9. Difference between abstract class and Interfaces 10. What is a view..? Does a view contain data..? 11. What are triggers..? 12. What are transactions..? 13. What is Metaview (oracle)..? 14. What is Inheritance..? How can we call a method from the base class..? 15. Can an abstract class have zero abstract methods..? 16. How to read from Message Queue..? 17. What is Metadata..? 18. You would prefer to have business logic in c# or DB Side..? Why…?

1 Answers   Franklin Templeton, Sky InfoTech,


How do you set language in web.cofig ?

3 Answers   Keane India Ltd,


How dataadapter.fill works?

0 Answers  


Who generates session id?

0 Answers  


how to include timer or counting time to display next page in asp.net

0 Answers  


What is the meaning of TestApi?

0 Answers  


Categories