try-catch-finally问题
本想用下面代码来实验一下try-catch-finally问题,结果当(x*x-y*y)<0时,并没有象预料中那样执行catch{}跪求解答
static void Main()
{
double x,y;
double z=0;
x = double.Parse(Console.ReadLine());
y = double.Parse(Console.ReadLine());
try
{
z = Math.Sqrt(x*x-y*y);
Console.Write("~~~try");
}
catch
{
z = Math.Sqrt(y*y-x*x);
Console.Write("~~~catch");
}
finally
{
z = z + x;
Console.Write("~~~finally");
}
Console.WriteLine("z = {0}",z);
Console.Read();
}