try-catch-finally — exception handling.
Basic:
1try2{3 var data = await GetDataAsync();4}5catch (HttpRequestException ex)6{7 Console.WriteLine($"HTTP error: {ex.Message}");8}9catch (Exception ex)10{11 Console.WriteLine($"Error: {ex.Message}");12 throw; // Re-throw13}14finally15{16 Cleanup();17}
Exception filters:
1catch (Exception ex) when (ex.Message.Contains("timeout"))2{3 // Handle timeout4}
Key: Catch specific exceptions, use finally for cleanup.