Join Reynald Adolphe for an in-depth discussion in this video Using await in catch and finally blocks, part of C# 6.0 First Look.
- C# 5 introduced the ability to run asynchronous methods…using the await and async keywords.…However there are some limitations when handling exceptions…because you couldn't use it in a catch or finally block.…On my screen I have a copy of Visual Studio 2013.…And as you can see the compile a complaint,…but you cannot await in a catch and finally clause.…But in version 6.0 you can,…and the most common reason you'd even want…to implement this feature is if you're logging errors.…
It's something that might take a few seconds,…so you don't want to freeze up the UI.…Let's give it a try and demonstrate an approach…to log with async prior to 6.0,…and then with the new version of C#.…The first thing I'm going to want to do…is go ahead and create a method just to log our data.…So let's go ahead and start by stating…private static async,…specify task,…and we'll call this LogDataAsync.…
Let's go ahead and pass in…some details with an exception.…Now let's go ahead and start a using block.…The shortcut I like to use is just to type in using…
- Introducing the new IDE in Visual Studio 2015
- Leveraging nameof expressions
- Using index initializers
- Using await in catch and finally blocks
- Using static
- Resolving conflict instance methods
Skill Level Beginner
1. Touring the Enhanced IDE
2. Expression-Level Features
3. Statement-Level Features
Adding exception filters2m 42s
4. Member Declaration and Initialization Features
5. Improved Debugging
- 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.