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

Try Catch While Retry!

$
0
0
Hi. My main window open another custom window, and I have to enter 5 different text fields. If the number enter is negative then it would catch an error, and must return to that custom window to re-enter the correct one.

Here is the place where it catch an error, but I don't know how to do it correctly.
        public StockPrice getStockPrice()
        {
            StockPrice s = new StockPrice();
            while (true){
            try
            {
                s.CompanyName = companyNameTB.Text;
                s.Stock = stockTB.Text;
                s.OpeningPrice = double.Parse(openingPriceTB.Text);
                s.HighPrice = double.Parse(highPriceTB.Text);
                s.LowPrice = double.Parse(lowPriceTB.Text);
                s.ClosingPrice = double.Parse(closePriceTB.Text);
                break;
            }
            catch (Exception ex)
            {
               MessageBox.Show(this, "Error: " + ex.Message);
            }}
            return s;
        }
    }

Viewing all articles
Browse latest Browse all 51036

Trending Articles