How to throw an caught exception from cath block?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Are tuples mutable c#?
What is private variable?
Which language is used for desktop application?
Difference between debug.write and trace.write?
What?s the difference between the Debug class and Trace class?
What are the 3 different types of arrays?
Difference between a sub and a function in c#.
Why constructor is used in c#?
What are data types examples?
What is the default value of guid in c#?
Why do we use struct in c#?
Why do we need static in c#?