Why do we need a finally block in try catch block while
handling exceptions

Answers were Sorted based on User's Feedback



Why do we need a finally block in try catch block while handling exceptions..

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

Why do we need a finally block in try catch block while handling exceptions..

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

Why do we need a finally block in try catch block while handling exceptions..

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

Why do we need a finally block in try catch block while handling exceptions..

Answer / amit

when we need to forcefully executed the code even any
exception will occurs.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What are logical operators in c#?

0 Answers  


What is a thread c#?

0 Answers  


What happens if you add duplicate elements to a set?

0 Answers  


What?s a satellite assembly?

2 Answers  


hi, I am a begineer to c sharp. I have written a code for finding out prime numbers. Can anyone identify what are the flaws in my code. Kindly donot complex the code or present logic because i am new to c sharp and just started learning programming language.Thanks in advance. class Program { static void Main(string[] args) { int a,b=1; a = int.Parse(Console.ReadLine()); c= int.Parse(Console.ReadLine()); if (a % b == 0 && a % 2 != 0 && a % a == 0) Console.WriteLine(a); else if (a % b == 0 && a % 2 == 0) Console.WriteLine(a%2); Console.WriteLine("Number is not PRIME"); Console.ReadLine(); } } }

2 Answers  






What is the difference between field and variable in c#?

0 Answers  


What is collection class c#?

0 Answers  


Any exceptions are there which are not caught by any catch blocks? what are they?

5 Answers   Honeywell, TCS,


I created a class which is inherited from interface IDisposable. Now if I use object of this class with using keyword. Then How the dispose method will get call. Does garbage collector call it or some else.

2 Answers   Sapient,


What is lambda expression in c#?

0 Answers  


What is c# most used for?

0 Answers  


What is .edmx file?

0 Answers  


Categories