Minggu, 06 Maret 2011

Contoh Exception Handling

using System;

namespace Exception_Handling
{
   
    class Class1
    {
       
        [STAThread]
        static void Main(string[] args)
        {
            char ulg;
            int a;
            Console.WriteLine("Program Exception Handling");
            do
            {
            b:
                try
                {
                    Console.Write("\n\nMasukkan NIM anda : ");
                    a=Convert.ToInt32(Console.ReadLine());
                }
                catch
                {
                    Console.WriteLine("Maaf Nama Harus dalam tipe Integer !!!");
                    goto b;
                }
           
            Console.WriteLine("Tipe NIM anda benar !!");
            Console.Write("\nIngin Mencoba Lagi [Y/T]? : ");
            ulg=Convert.ToChar(Console.ReadLine());
        }while(ulg=='Y' || ulg =='y');
            Console.ReadLine();
        }
    }
}

Hasilnya akan tampak seperti gambar dibawah ini :


0 komentar:

Posting Komentar

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Online Project management