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 compiled object?

1652


Explain the use of view state?

572


How can you handle errors in Web API?

609


What is the difference between cookie and session?

508


What r the asp.net list controls and diff. Between them?

515






Why do we need a web application session?

521


Explain about ASP.NET?

643


What are the advantages of asp.net?

552


Is session server side or client side?

538


We Only Know The Total Number Of Feet In The Farmyard. Write A Program that will compute the total number of rabbits and chickens in the farmyard. Assume number of feet in the farmyard are 40. how many rabbits and chickens are?

449


8. Why do you want to work here?

1488


Explain how is a property designated as read-only?

561


How is my content secured from unauthorized access?

528


What are the authentication types in asp.net?

584


What is latest version of asp.net mvc? : Asp.Net MVC

485