Join Anton Delsink for an in-depth discussion in this video File.Close in the finally block, part of Object Oriented Programming with C#.
- [Instructor] Now that we've seen how to open a file,…and noted that we are supposed to call the close method…to release this limited resource,…I'll copy and paste the method, rename the method…call this 011, and so now the way we would…typically do this if we had no further help…from the compiler or any other subsystems…we would say try, catch…and then here at the end, in the catch block…we would handle any errors that we can handle…and any errors we cannot handle would go to the caller,…would go to whatever method is calling…this public void test, 011.…
And so, we would have one last chance…in the finally block to clean up.…So what this means is if we don't have a catch block,…if we cannot handle the exception so to speak,…if the exception has to go to the caller,…we still have the finally block as a last…opportunity to clean up the resources that we gained…access to within this tri-block.…So the way this works, the pattern typically…has a variable here on the outside.…
In this case, fs, and I'll initialize that to null for now,…
- Abstract classes
- Processing text with StreamReader
- IEnumerable and yield return
- Windows Forms controls
- Windows Forms with and without the designer
- Adding, organizing, and testing forms
- Creating classes
Skill Level Intermediate
C# Object-Oriented Programming Tips and Trickswith Jesse Freeman58m 39s Intermediate
What you should know1m 10s
1. Theory vs. Practice
2. Examples from .NET
3. Examples from Windows UI
4. Examples from Board Games
5. Examples from the Web
Next steps1m 13s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.