Can we throw exception from catch block ?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between user control an custom control?

617


What is owin authentication?

520


What are uri parameters?

545


When you are running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?

596


What should you do is you want to remove an existing component but would like to make some funtionalities?

1482






Is asp.net web forms dead?

513


Explain the difference between codebehind="mycode.aspx.cs" and src="mycode.aspx.cs"?

538


How do I publish my asp.net application to my isp's web server?

590


What is the use of session in web application?

485


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

544


What are the different types of proxy patterns?

596


What is inheritance and an how it be used, example with an example?

586


Can user control be stored in library?

521


Explain model, view and controller represent in an mvc application? : asp.net mvc

519


What is the difference between rest and restful?

538