static void Test() { try { SomeOperation(); } catch (Exception e) when (e.InnerException is OperationCanceledException oce) { Console.WriteLine($"Operation was cancelled: {oce}"); } }