Description
When we transitioned to the current version of exercism, we removed the generic "raising exceptions" notices from all the exercise READMEs. We felt they were adding confusion and leading students to insert error raising and handling in places where they should not have been inserting it.
For the Python track, we were (and are!) planning error handling
concept exercises to help students learn how to raise and handle errors properly in their code.
But those exercises are still in process, and we have 42 practice exercises that test for error handling in one way or another.
37 of these include JinJa2
test generation templates.
As a stopgap while we create the error handling
concept exercises, we need to create practice exercise .docs/instructions.append.md
files for the 42
exercises that add back a blurb about how to raise an exception. The original vs proposed language for the instructions.append.md
is at the bottom, but is open to any edits that make sense and help student understanding.
For the 37 JinJa2
exercises, we will need to modify the test generation templates to test for a meaningful exception message, and not just the presence of any exception. We'll then need to regenerate those test files.
For the 5 exercises that remain, we will need to hand-edit the test files as opposed to editing a generation template.
Recommend that a PR for ONE exercise be done as a first pass to make sure the changes do indeed makes sense, then the remainder of them can be done.
These are the 42 practice exercises in question:
- affine-cipher | test file | template file
- all-your-base | test file | template file
- bank-account | test file
- binary-search | test file | template file
- binary | test file
- bowling | test file | template file
- change | test file | template file
- circular-buffer | test file | template file
- collatz-conjecture | test file | template file
- dot-dsl | test file
-
error-handling | test fileExercise has been depreciated. - forth | test file | template file
- go-counting | test file | template file
- grains | test file | template file
- hamming | test file | template file
- hangman | test file
-
hexadecimal | test fileExercise has been depreciated. - largest-series-product | test file | template file
- meetup | test file | template file
- minesweeper | test file | template file
- nth-prime | test file | template file
-
nucleotide-count | test fileExercise has been depreciated. - ocr-numbers | test file | template file
-
octal | test fileExercise has been deprciated. - palindrome-products | test file | template file
- perfect-numbers | test file | template file
- phone-number | test file | template file
- pov | test file
- queen-attack | test file | template file
-
rational-numbers | test file | template fileactually, no error cases here. -
robot-simulator | test file | template fileNo error cases currently. Consider adding some later. -
roman-numerals | test file | template fileDoesn't have error cases either. Maybe we should consider adding some. -
run-length-encoding | test file | template fileNo error cases. - saddle-points | test file | template file
- satellite | test file | template file
- say | test file | template file
- series | test file | template file
- sgf-parsing | test file | template file
- simple-linked-list | test file
- tree-building | test file
- variable-length-quantity | test file | template file
- wordy | test file | template file
The original and proposed new error handling
messages are below.
[ORIGINAL]
Exception messages
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include a message.
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of raise Exception, you should write:
raise Exception("Meaningful message indicating the source of the error")
[Suggested Changes]
Exception messages
Sometimes it is necessary to raise an exception. When you do this, you should always include a meaningful error message to indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. For situations where you know that the error source will be a certain type, you can choose to rase one of the built in error types, but should still include a meaningful message.
This particular exercise requires that you use the raise statement to "throw" an exception
. The tests will only pass if you both raise
the exception
and include a message with it.
To raise an exception
with a message, write the message as an argument to the exception
type:
raise Exception("Meaningful message indicating the source of the error")