Why do we need a finally block in try catch block while
handling exceptions
Answers were Sorted based on User's Feedback
Answer / vijay kumar inumella
finally block will be executed irrespective of whether
the exception occured or not.
finally block is generally used to close the database
connections and to dispose the session objects etc.
| Is This Answer Correct ? | 12 Yes | 1 No |
Answer / linto
For releasing unmanaged related objects from Garbage
collector.While,exception happen,the process flow may be
change.At that situation unmanaged objects like database
connection etc should be close.For that purpose we are
using finally block in try catch block.But,Idisposable is
better in the case of efficiency.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / santosh
The code which should execute at any cost even when an exception occurs that code should be written in finally block
ex-closing a form when exception occurs.
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / amit
when we need to forcefully executed the code even any
exception will occurs.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is datagrid c#?
What is the root element of an xml file?
What Is A Multicast Delegate?
How to prevent the error while updating ui control from another thread?
Where static variables are stored?
can we throw execption from catchblock
Can non-default constructors be used with single call sao?
What is linq c#?
Can multiple catch blocks be executed?
You have got 1 million parking slots. At a time a parking slot can be free or not. To get next slot easily which data structure to implement?
Why do we need abstraction in c#?
Can we have private constructor in our class file. When we are trying to create instance for the class will it create or throw error regarding that?
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)