1. 程式人生 > >C# 的異常處理

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();



    }
}

}