Part of the difficulty of handling exceptions is doing clean-up. Suppose you open a database and move a record from one table to another, but you receive an exception before you have a chance to close the database. If you leave the function without closing the database, your program will consume more memory and limit the number of connections from other users to the same database. C# provides a language construct that works in conjunction with the try/catch block that enables you to specify code that should run before you exit a function (whether you exit because of an exception or simply exit because the function is done executing). To add code that triggers automatically before a function exits, you must add a finally block. To add a finally block:
Tips
|