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 an iHTTPModule, and explain its implementation with its limitations?

1 Answers   Siebel,


Explain the namespace classes used in asp.net mvc? : asp.net mvc

0 Answers  


What is http request and response?

0 Answers  


What is the first name space in .netF/W heirarchy

3 Answers   Wipro,


How many view state can be hold by a aspx page ?

3 Answers   Intellevate,






In the context of a comparison, what is object identity versus object equivalence?

1 Answers  


Can you use Web API with ASP.NET Web Form?

0 Answers  


What is cookie less session? How it works?

2 Answers   TCS,


hi .net gurus. plz if any one has dumps on 70-631 and 70-541 on windows sharepoint services kindly mail me.

0 Answers  


What is break mode?

0 Answers  


What symbol would you use to denote, the start of a code block in aspx views?

0 Answers   NA,


What are the benefits of Razor View?

0 Answers   NA,


Categories