- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
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);
}
}
}