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 the characteristics of c#?

0 Answers  


What is the difference between <c> and <code> xml documentation tag?

0 Answers  


What is readline c#?

0 Answers  


How long will it take to learn c#?

0 Answers  


3. Describe the process of interact UI to BAL n DAL?

2 Answers   Mphasis,






What is Custom attribute? How to create? If I'm having custom attribute in an assembly, how to say that name in the code?

0 Answers  


Can you have parameters for static constructors?

0 Answers  


Why data types are important in c#?

0 Answers  


How can you overload a method?

3 Answers  


How many dimensions can an array have?

0 Answers  


what is class libraries?

1 Answers  


What does a constructor do c#?

0 Answers  


Categories