Как сгенерировать собственное исключение - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace CLAb
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
treyg Tr = new treyg();
treyg Tr1= new treyg(5,6);
treyg Tr2;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button2Click(object sender, EventArgs e)
{
if (Tr2!=null)
{
textBox3.Text=Tr2.Pr().ToString();
textBox4.Text=Tr2.S().ToString();
textBox1.Text=Tr2.get_a().ToString();
textBox2.Text=Tr2.get_c().ToString();
}
}
void Button3Click(object sender, EventArgs e)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox4.Text="";
}
void Button4Click(object sender, EventArgs e)
{
treyg Tr4= new treyg(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
textBox3.Text=Tr4.Pr().ToString();
textBox4.Text=Tr4.S().ToString();
}
void RadioButton1CheckedChanged(object sender, EventArgs e)
{
Tr2=Tr;
}
void RadioButton2CheckedChanged(object sender, EventArgs e)
{
Tr2=Tr1;
}
void Button1Click(object sender, EventArgs e)
{
if (Tr2!=null)
{
Tr2.set_a(double.Parse(textBox1.Text));
Tr2.set_c(double.Parse(textBox2.Text));
}
else {label6.Text="Вы не выбрали ни один объект";}
}
}
class treyg{
private double a,c;
public void set_a(double aa)
{
try
{ Console.WriteLine("");
if(a<2 && a>11);
}
catch
(FormatException u)
{
MessageBox.Show ("Ошибка в данных!");
}
if (aa>=2 && aa<=11)
{ a=aa;}
else a=2;
}
public void set_c(double cc)
{
if (c>=2 && cc<=11)
{c=cc;}
else c=2;
}
public double get_a()
{
return a;
}
public double get_c()
{
return c;
}
public double Pr() {return (c+2*a);}
public double S() {return (0.5*a*Math.Sqrt(a*a-0.5*c*0.5*c));}
//Создание конструктора
public treyg(){a=5; c=8;}//конструктор по умолчанию
public treyg (int aa, int cc)// конструктор с параметром
{
if ( (aa>=2) && (aa<=11))
{
a=aa;
}
else a=2;
if ( (cc>=2) && (cc<=11))
{
c=cc;
}
else c=2;
}
}
}Решение задачи: «Как сгенерировать собственное исключение»
textual
Листинг программы
throw new Exception("а это исключение я бросил сам");