using System;
namespace practicerandom
{
class Program
{
static void Main(string[] args)
{
Random rdm = new Random();
int guess = rdm.Next(0, 101);
bool temp = false;
try
{
int j = 0;
do
{
Console.WriteLine("请输入一个0到100之间的整数");
string sGuess = Console.ReadLine();
int Guess = int.Parse(sGuess);
if (Guess < 0 || Guess > 100)
throw new Exception("The integer does not meet the requirement!");
else if (Guess == guess)
{
temp = true;
j++;
Console.WriteLine("这是第{0}次猜,恭喜你,猜对了!",j);
}
else if (Guess > guess)
{
j++;
Console.WriteLine("这是第{0}次猜,太大了",j);
}
else if (Guess < guess)
{
j++;
Console.WriteLine("这是第{0}次猜,太小了",j);
}
} while (temp != true);
}
catch (Exception e)
{
Console.WriteLine("发生的错误为:"+e.Message);
}
}
}
}
try catch语句的使用以及如何抛出异常