I'm writing a Xamarin.Android app (no domain knowledge is required, though). I have an async void
method that looks like this:
protected override async void OnCreate(Bundle savedInstanceState)
{
// Some synchronous code
await SetupEditor(EditorTheme.Default);
}
I've written my app such that the task returned from SetupEditor(...)
will cancel if the user clicks the back button. However, when I click the back button, the app crashes here with a TaskCanceledException
. I'd like to rewrite this to
protected override async void OnCreate(Bundle savedInstanceState)
{
// Some synchronous code
try
{
await SetupEditor(EditorTheme.Default);
}
catch (TaskCanceledException)
{
return;
}
}
Is there a more concise way to do this without using a try/catch block? I wouldn't want to write 7 lines every time I wanted to await a task like this. Thanks.