クエリにおける例外処理について。
成果物
情報源
- https://docs.microsoft.com/ja-jp/dotnet/csharp/linq/handle-exceptions-in-query-expressions
- https://docs.microsoft.com/ja-jp/dotnet/standard/exceptions/best-practices-for-exceptions
コード
クエリ前
using System; using System.Collections.Generic; using System.Linq; class Main { public void Run() { IEnumerable<int> dataSource; try { dataSource = GetData(); } catch (InvalidOperationException) { Console.WriteLine("Invalid operation"); goto Exit; } var query = from i in dataSource select i * i; foreach (var i in query) { Console.WriteLine(i.ToString()); } Exit: Console.WriteLine("Press any key to exit"); Console.ReadKey(); } private IEnumerable<int> GetData() {throw new InvalidOperationException();} }
クエリ後
using System; using System.Collections.Generic; using System.Linq;
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 5.0.3(1)-release
$ uname -a Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux