Avatar ·

How to catch multiple exception types in one catch block in C#?

Hi everyone! I'm a beginner C# developer, and I've encountered a problem with exception handling. I'm writing a small application for working with files and a database. I have code that can throw several different exceptions: for example, `FileNotFoundException` (if the file is not found), `IOException` (reading issues), and `SqlException` (database connection error).\n\nCurrently, I handle them like this:\n\n```csharp\ntry\n{\n // code that can throw multiple exceptions\n}\ncatch (FileNotFoundException ex)\n{\n Console.WriteLine("File not found: " + ex.Message);\n}\ncatch (IOException ex)\n{\n Console.WriteLine("Input/output error: " + ex.Message);\n}\ncatch (SqlException ex)\n{\n Console.WriteLine("Database error: " + ex.Message);\n}\n```\n\nBut this looks very cumbersome, and I