try { double n; n = Convert.ToDouble(numberbox.Text); if (n <= 0) n = 0.0001; if (numberbox.Enabled == true) { s = n; if (radgrad!=null) if (!radgrad.Checked) s*=Math.PI/180; } if (functions.cut(s, 4) != s) { numberbox.Text = functions.cut(s, 4).ToString();//it is on this line that I get the exception if (radgrad != null) if (!radgrad.Checked) numberbox.Text = functions.cut(180 * s / Math.PI, 4).ToString(); } } catch (StackOverflowException) {//I don't get to know if this code is ever excecuted, since the error message freezes the program if (numberbox.Text == "") { numberbox.Text = "1"; if (numberbox.Enabled == true) s = 1; } else { numberbox.Text = functions.cut(s, 4).ToString(); if (radgrad != null) if (!radgrad.Checked) numberbox.Text = functions.cut(180 * s / Math.PI, 4).ToString(); } } catch (Exception) { if (numberbox.Text == "") { numberbox.Text = "1"; if (numberbox.Enabled == true) s = 1; } else { numberbox.Text = functions.cut(s, 4).ToString(); if (radgrad != null) if (!radgrad.Checked) numberbox.Text = functions.cut(180 * s / Math.PI, 4).ToString(); } }

When the exception happens, n is 0.0001 and s is like 100 000 times smaller than that.