using System; namespace Test { public class HttpException : Exception { public HttpException(int status) { StatusCode = status; } public int StatusCode { get; set; } } class Program { static void TestCatch(int status) { try { throw new HttpException(status); } catch (HttpException ex) when (ex.StatusCode == 404) { Console.WriteLine("Not Found!"); } catch (HttpException ex) when (ex.StatusCode >= 500 && ex.StatusCode < 600) { Console.WriteLine("Server Error"); } catch (HttpException ex) { Console.WriteLine("HTTP Error {0}", ex.StatusCode); } } static void Main(string[] args) { TestCatch(404); TestCatch(501); TestCatch(101); } } }