Explain why we should close and dispose resources in a Finally block instead of Catch block.Catch block gets called only when an exception occurs or is explicitly thrown but we need to release our resources in either case (task failure or success). Finally block gets called irrespective of what happens in try. For example: we fetch data from database. In this case the first step would be creating a connection in order to access the database. Once our work is done successfully or if our logic crashes we need to end the connection so we write it in a finally block.
|