I am designing a simple calculator using Visual C #, but I run into an annoying runtime error (which is ridiculous for a statically typed language).
First let me show you a partial code:
private float get_input()
{
try
{
return float.Parse(textBox1.Text);
}
catch
{
textBox2.Clear();
textBox2.AppendText("Invalid Input");
return 0;
}
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Clear();
float v = get_input();
textBox2.AppendText((Math.Sin(v)).ToString());
}
The problem is that when I run the program and, for example, say that I entered "a" in the input field, my program handles the exception by displaying "Invalid input" in the output field. However, then it computes the values sinor cos(etc.) of the float type by default. Thus, the answer in the output field will look like this: "invalid input 1" or "invalid input signal0". I provided a screenshot:

, , , get_input(), , . 7 , - .