Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:37+00:00 2026-06-13T11:43:37+00:00

what I am trying to do is use a try-catch exception to restart the

  • 0

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.

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  

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:43:38+00:00Added an answer on June 13, 2026 at 11:43 am

    When you start learning to program you learn that these situations can be solved using while or do-while loops. Therefore I will give you such answer:

                bool restart = false;
                do
                {
                    restart = false;
                    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");
                        restart = true;
                    }
                } while (restart);
    

    Watch out that if you call Main within Main you can end up making StackOverflowException 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use try-catch blocks to handle a divide-by-zero exception in marmalade,
How to correctly let an exception to bubble up? If I use Try-Catch when
I'm trying to use Subsonic 3.0 but with every query I try it gives
I'm trying to use the MiscUtil.Conversion utility in Silverlight. http://www.yoda.arachsys.com/csharp/miscutil/ When I try to
I am need paint my image. I'm trying use JQuery in here this link:
I'm trying to use ksoap to call a simple webservice. I followed this video
I am trying to catch 'Trying to get property of non-object' error with a
I'm trying to use SpringJunit4ClassRunner to test my DAO classes without leaving data behind
Hi I'm working with winform and trying to use MessageBox for exception handling. The
I trying to use the Open Session in View pattern, but everytime I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.