There are some people on my team who really love coding with async Task
. And sometimes they like to use CancellationToken
parameters.
What I\'
In the .Net framework itself when you pass a CancellationToken as a parameter you will get back a TaskCanceledException. I would not go against that and create my own design pattern because people who are familiar with .Net will be familiar with your code.
My guideline is this: The one that cancels the token is the one that should handle the TaskCanceledException
, so If you're using a CancellationToken
inside your method for your own reasons, go ahead and use a try-catch
block. But if you get the token as a parameter, let the exception be thrown.