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

Why we use asp.net for website development?

675


What is a server cookie?

702


How to disable disable browser's Back button in asp.net (JavaScript)?

792


Describe the method to create a permanent cookie?

779


How to create events for a control?

750


How ASP and ASP.NET page works? Explain about asp.net page life cycle?

764


Write a code for sending an email from asp.net application.

756


How do you do Client-side validation in .Net?

810


How to implement globalization and localization in the use interface in .net.

734


Explain the different parts that constitute ASP.NET application?

754


What is the difference between web.config and machine.config in ASP.NET?

809


What does session_start () do?

817


Can we store object in viewstate?

736


What are the ways of preserving data on a Web Form in ASP.NET?

809


Explain the difference between server control and html control.

685