Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Catch clause fails to 'catch' the exception

$
0
0
I get a stackoverflow error message regardless that I have the corresponding catch clause. My question is not why the exception happens or what in my code causes it, but rather why I get the error message even when I have the corresponding catch clause.
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.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>