异常 集中异步处理
public class DataStorage { public async Task WriteFile(string key, object value) { try { var jsonValue = JsonConvert.SerializeObject(value); using (var file = await folder.OpenStreamForWriteAsync(key, CreationCollisionOption.ReplaceExisting)) using (var stream = new StreamWriter(file)) await stream.WriteAsync(jsonValue); } catch (Exception exception) { AsyncErrorHandler.HandleException(exception); } } }
public static class AsyncErrorHandler { public static void HandleException(Exception exception) { Debug.WriteLine(exception); } }
https://github.com/Fody/AsyncErrorHandler/blob/master/README.md