AS 2019 DisplayErrorMessages

From TRCCompSci - AQA Computer Science
Revision as of 09:53, 1 April 2019 by Admin (talk | contribs) (Where)
Jump to: navigation, search

Where

The SetupBoard method has a try & catch block, this runs DisplayErrorCode(4) , this will be an error when loading the file.

The SelectMove method has a try & catch block, this runs DisplayErrorCode(3) (approx line 440), this will be an error cause by entering a non integer value for the Row or Column.

The SelectMove method also runs DisplayErrorCode(1) (approx line 399), this be displayed because the piece doesn't exit.

The SelectMove method also runs DisplayErrorCode(2) (approx line 428), this will be displayed when the piece you are trying to move can't move. ie it is not in the list of possible moves.

The method called is:

        private static void DisplayErrorCode(int errorNumber)
        {
            Console.WriteLine("Error " + errorNumber);
        }

Idea

You should add a Switch..Case statement after the current Console.WriteLine to also display a message to explain the error. So you could:

        private static void DisplayErrorCode(int errorNumber)
        {
            Console.WriteLine("Error " + errorNumber);
            string message = "";
            switch(errorNumber)
            {
                case 1:
                    message = "Piece does not exist";
                    break;
                case 2:
                    message = "Piece can't move";
                    break;
                case 3:
                    message = "Invalid position";
                    break;
                case 4:
                    message = "File error";
                    break;
            }
            Console.WriteLine(message);
        }