How to throw an caught exception from cath block?

Answers were Sorted based on User's Feedback



How to throw an caught exception from cath block?..

Answer / lonesloane

try{
// code that throws exception
}
catch(Exception ex){
// Do whatever needed with exception
Console.Writeline(ex.Message);
throw; <== will re-throw the caught exception
}

Is This Answer Correct ?    3 Yes 0 No

How to throw an caught exception from cath block?..

Answer / gustav bouwer

This (as above) will re throw the exception.

catch (Exception e)
{
throw e;
}

This passes along the ORIGINAL exception so you keep your
stack trace.
catch (Exception e)
{
throw;
}

Is This Answer Correct ?    3 Yes 0 No

How to throw an caught exception from cath block?..

Answer / chandana

use the 'throw' keyword to throw an exception from a catch
block. ex,

catch (Exception e)
{
throw e;
}

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More C Sharp Interview Questions

What are floating point numbers?

0 Answers  


What is the difference between namespace and class?

0 Answers  


Is char * null terminated?

0 Answers  


How do I format a string in c#?

0 Answers  


How do you achieve polymorphism in c#?

0 Answers  






What is the usage of transponders?

0 Answers   Wipro,


Is it possible to implement an interface to a structure? Is it possible to extend a struct? Is it possible to inherit a class to struct?

9 Answers   IBM, Logica CMG, TCS,


What is boolean conditions in c#?

0 Answers  


Can an Assembly have multiple versions

13 Answers   TCS,


Can you prevent a class from overriding?

3 Answers  


What's the implicit name of the parameter that gets passed into the set method/property of a class?

0 Answers  


What is enumerable in c#?

0 Answers  


Categories