C# 的异常处理

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B_8_1
{
class Program
{
static void Main(string[] args)
{
int num1, num2, resu;
try
{
num1 = Int32.Parse(args[0]);
num2 = Int32.Parse(args[1]);
resu = num1 / num2;
Console.Write(“{0}除以{1}的商为:{2}”, num1, num2, resu);

        }
        catch (IndexOutOfRangeException) {
            Console.Write("输入参数不够!");
                    }
        catch (FormatException)
        {
            Console.Write("输入参数格式错误!");
        }
        catch (DivideByZeroException)
        {
            Console.Write("被除数为0");
        }
        catch (OverflowException)
        {
            Console.Write("超出运算空间");
        }
        Console.ReadKey();



    }
}

}

你可能感兴趣的:(C#,c#,异常处理)