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

Are tuples mutable c#?

0 Answers  


What is private variable?

0 Answers  


Which language is used for desktop application?

0 Answers  


Difference between debug.write and trace.write?

0 Answers  


What?s the difference between the Debug class and Trace class?

2 Answers   Siebel,






What are the 3 different types of arrays?

0 Answers  


Difference between a sub and a function in c#.

0 Answers  


Why constructor is used in c#?

0 Answers  


What are data types examples?

0 Answers  


What is the default value of guid in c#?

0 Answers  


Why do we use struct in c#?

0 Answers  


Why do we need static in c#?

0 Answers  


Categories