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 is difference between Method and function

3 Answers  


How can I develop an application that automatically updates itself from the web?

0 Answers  


What are properties and indexer?

1 Answers   TCS,


can u tell me any one steps for creatting sn.k

2 Answers  


What are the types of access modifiers?

0 Answers  






If you define a user defined data type by using the struct keyword, is it a value type or reference type?

0 Answers  


How you will connect to windows directory in c#?

2 Answers   HP, nTech Solutions,


What does readonly mean in c#?

0 Answers  


What is inheritance c#?

0 Answers  


What?s the role of the DataReader class in ADO.NET connections?

2 Answers  


What is a namespace server?

0 Answers  


What is namespace c#?

0 Answers  


Categories