Skip to content

Commit 080c40b

Browse files
BethanyGYrahcaz7
andauthored
[State of Tic Tac Toe]: Added missing instruction append for raising errors. (#4242)
* Added missing instruction append for raising errors. * Removed extra bracket. * Update exercises/practice/state-of-tic-tac-toe/.docs/instructions.append.md Co-authored-by: Yrahcaz <74512479+Yrahcaz7@users.noreply.github.com> --------- Co-authored-by: Yrahcaz <74512479+Yrahcaz7@users.noreply.github.com>
1 parent cc74d5c commit 080c40b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Instructions append
2+
3+
## Exception messages
4+
5+
Sometimes it is necessary to [raise an exception][raising-exceptions].
6+
When you do this, you should always include a **meaningful error message** to indicate what the source of the error is.
7+
This makes your code more readable and helps significantly with debugging.
8+
For situations where you know that the error source will be a certain type, you can choose to raise one of the [built in error types][error-base-classes], but should still include a meaningful message.
9+
10+
11+
A valid game of `Tic Tac Toe` ends when one player wins.
12+
If both players are in a winning state, this exercise expects you to use the [raise statement][raise] and "throw" a `ValueError` in your solution.
13+
Your code is also expected to throw a `ValueError` if one player is assessed as playing two turns in a row, or playing the first move when they were assigned to play the second move.
14+
15+
16+
To raise a `ValueError` with a message, write the message as an argument to the `exception` type:
17+
18+
```python
19+
# Example when player X goes before player O.
20+
raise ValueError("Wrong turn order: O started")
21+
22+
# Example when player X goes twice.
23+
raise ValueError("Wrong turn order: X went twice")
24+
25+
# Example when player X wins AND player O wins.
26+
raise ValueError("Impossible board: game should have ended after the game was won")
27+
```
28+
29+
The tests will check for an exact error message match, so please read the expected results carefully.
30+
31+
[raising-exceptions]: https://docs.python.org/3/tutorial/errors.html#raising-exceptions
32+
[error-base-classes]: https://docs.python.org/3/library/exceptions.html#base-classes
33+
[raise]: https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement

0 commit comments

Comments
 (0)