Page 63 - E-Modul Pemrograman Dasar Kelas X
P. 63

  Stack Overflow Exception
                            Dan lain-lain

                              Ada  beberapa  langkah  untuk  menjalankan  program  exception  handling  yaitu
                       sebagai berikut.

                       1)  Menggunakan exception clas dari C# untuk menghindari adanya kesalahan pada saat
                          program dijalankan. Sebagai contoh seperti program berikut ini.


                        using System;
                        using System.Collections.Generic;
                        using System.Linq;

                        using System.Text;

                        namespace ConsoleApplication1
                        {

                               class Program
                               {
                                       class siswa
                                       {
                                       int res;

                                       public void tampilkan(int a, int b)
                                       {
                                              try
                                              {

                                                     res = a / b;
                                                     Console.WriteLine(res);
                                              }
                                              catch (DivideByZeroException e)
                                              {

                                                     Console.WriteLine(e.Message);
                                              }
                                              catch (FormatException ex)
                                              {

                                                     Console.WriteLine(ex.Message);
                                              Catch
                                              {





                                                             54
   58   59   60   61   62   63   64   65   66   67   68