1) SystemException -> CLR & .NET Framework
2) ApplicationException -> aplikasi
Statement try
try-catch-finally
2) ApplicationException -> aplikasi
Statement try
try-catch-finally
static void Main(String[] args)
{
try
{
//operasi yang mungkin menghasilkan
exception
}
catch
{
//penanganan exception
}
finally
{
//langkah2 yang harus selalu dilakukan
//ada atau tidak exception
}
}
Contoh:
static void Main(String[] args)
{
try
{
System.Console.WriteLine("Masukkan angka
pembagi");
int angka = Convert.ToInt32(System.Console.ReadLine());
if (angka == 0)
{
throw new Exception("Angka tidak boleh
0");
}
System.Console.WriteLine("Angka yang dimasukkan
= " + angka);
}
catch
(Exception ex)
{
System.Console.WriteLine(ex.Message);
}
finally
{
System.Console.WriteLine("Proses selesai
!");
}
System.Console.ReadKey();
}