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 |
What are floating point numbers?
What is the difference between namespace and class?
Is char * null terminated?
How do I format a string in c#?
How do you achieve polymorphism in c#?
What is the usage of transponders?
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#?
Can an Assembly have multiple versions
Can you prevent a class from overriding?
What's the implicit name of the parameter that gets passed into the set method/property of a class?
What is enumerable in c#?