c#da exception kullanıma örnek

try
{
decimal sonuc;
decimal tgelen1 = Convert.ToDecimal(textBox1.Text);
decimal tgelen2 = Convert.ToInt32(textBox2.Text);
if (tgelen2 < 0)
{
throw new hatayakala(“negatif”);
}

sonuc = (decimal)tgelen1 / tgelen2;
button1.Text = sonuc.ToString();
}
catch (DivideByZeroException hatamesajı)
{
MessageBox.Show(hatamesajı.Message);
}
catch (FormatException hatamesajı)
{
MessageBox.Show(hatamesajı.Message);
}
catch (OverflowException hatamesajı)
{
MessageBox.Show(hatamesajı.Message);
}
catch (Exception hatamesajı)
{
MessageBox.Show(hatamesajı.Message);
}

finally
{
label1.Text = “işlem sonlandı”;

textBox1.Text = null;
textBox2.Text = null;
textBox1.Focus();
}

tuna

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir