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 |
Why are strings immutable in c#?
What is the difference between int.parse and int.tryparse methods?
What is parse method in c#?
in object oriented programming, how would you describe encapsulation?
Why constructor is used in c#?
What is the difference between integer and double?
Why do we use 0?
What is the difference between var and dynamic types in c# 4.0?
Can property be private in c#?
Can datetime be null c#?
Can abstract class have constructor in c#?
What is int parse in c#?