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 r all the controls in ASP.NET ?

3 Answers  


What are validator? Name the validation controls in asp.net? How do you disable them? Will the asp.net validators run in server side or client side? How do you do client-side validation in .net? How to disable validator control by client side javascript?

0 Answers  


What does asp in asp.net stand for?

0 Answers  


How many languages are supported by .NET at present time?

0 Answers  


Where web.config file is used?

0 Answers   HCL,


Types of configuration files and their differences ?

2 Answers   Accenture,


Why would anyone need to implement their own hashtable or linked list?

0 Answers  


Is it possible to create web application with both webforms and mvc?

0 Answers  


Explain Generics?

1 Answers  


when the user control event occur in ASp page life cycle?

3 Answers   Microsoft,


Suppose you want a certain ASP.NET function executed on MouseOver over a certain button. Where do you add an event handler?

1 Answers   Zenith,


What is difference between session and viewstate?

0 Answers  


Categories