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 |
If a class is a ref type, how we can pass to a function.
Distinguish between array and arraylist in c#?
Different between method overriding and method overloading?
Explain the access modifiers in c#?
Can private virtual methods be overridden in c#.net?
Could you explain the difference between func vs action vs predicate?
What is the use of console readkey in c#?
Why do we need singleton pattern in c#?
What are c# types?
What are regular expressions? Search a string using regular expressions?
Between windows authentication and sql server authentication, which one is trusted and which one is untrusted?
What is difference between write and writeline?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)