Difference between revisions of "AS 2019 DisplayErrorMessages"
(Created page with "=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 blo...") |
(→Issue) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | = | + | =Issue= |
− | The SetupBoard method has a try & catch block, this runs DisplayErrorCode(4), this will be an error when loading the file. | + | The skeleton program has some built in error handling, some is based around exception handling and others are determined by the in-game logic. The program just displays an error code and no other information. The following errors are generated: |
+ | |||
+ | *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 | + | *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 | + | =Where= |
+ | The method called is: | ||
− | + | <syntaxhighlight lang=c#> | |
+ | private static void DisplayErrorCode(int errorNumber) | ||
+ | { | ||
+ | Console.WriteLine("Error " + errorNumber); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | =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: | ||
+ | <syntaxhighlight lang=c#> | ||
private static void DisplayErrorCode(int errorNumber) | private static void DisplayErrorCode(int errorNumber) | ||
{ | { | ||
Console.WriteLine("Error " + 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); | ||
} | } | ||
+ | </syntaxhighlight> |
Latest revision as of 08:57, 1 April 2019
Issue
The skeleton program has some built in error handling, some is based around exception handling and others are determined by the in-game logic. The program just displays an error code and no other information. The following errors are generated:
- 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.
Where
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);
}