Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a try-catch exception, within the catch brackets how do I restart the program if an exception occurs?
    primarykey
    data
    text
    <p>what I am trying to do is use a try-catch exception to restart the program and get the user to reeter the data values again. How would I do this? I tried using a goto to bring it back to the first line but this didn't seem to work. (and the general consensus is that goto's are evil). Any help that could be given greatly appreciated.</p> <pre><code>Console.WriteLine("Please enter the two points that you wish to know the distance between:"); string point = Console.ReadLine(); string[] pointInput = point.Split(' '); int pointNumber = Convert.ToInt16(pointInput[0]); //Stores the actual input number's into two integers int pointNumber2 = Convert.ToInt16(pointInput[1]); try //Try-Catch statement to make sure that the User enters relevant PointNumbers { double latitude = (Convert.ToDouble(items[pointNumber * 3])); // double longtitude = (Convert.ToDouble(items[(pointNumber * 3) + 1])); // double elevation = (Convert.ToDouble(items[(pointNumber * 3) + 2])); // double latitude2 = (Convert.ToDouble(items[pointNumber2 * 3])); // double longtitude2 = (Convert.ToDouble(items[(pointNumber2 * 3) + 1])); // double elevation2 = (Convert.ToDouble(items[(pointNumber2 * 3) + 2])); // Uses the relationship between the pointnumber and the array to select the required items from the array. //Calculate the distance between two point using the Distance class Console.WriteLine("The distance in km's to two decimal places is:"); Distance curDistance = new Distance(latitude, longtitude, elevation, latitude2, longtitude2, elevation2); Console.WriteLine(String.Format("{0:0.00}", curDistance.toDistance()) + "km"); } catch(IndexOutOfRangeException) { Console.WriteLine("You have selected a point number outside the range of the data entered, please select two new pointnumbers"); // here is where I would have the program restart } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload