やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

C#の概念 LINQ(例外)

 クエリにおける例外処理について。

成果物

情報源

コード

クエリ前

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;

対象環境

$ uname -a
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l GNU/Linux