Python Validation and Error Handling
Close the Buffer Even When a Line Is Bad
BOTIE
Examples, experiments and workspace controls
Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.
Try your own inputs
Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.
Context for this challenge
Open the buffer and read its lines. Inspect the values or error while closed is still false.
The text contains 4, a blank line, 7 and 3. Reading its whole-number lines gives a total of 14. The buffer must close afterward, including when a later example contains unreadable text.
Inspect the component calculation
Read the number lines(
Open buffer: Open the text buffer(
Lines as text: Buffer contents
)
)Examples and results
- Buffer contents
4 7 3
- Required result
- lines
- 0"4"
- 1""
- 2"7"
- 3"3"
- 4""
- values
- 04
- 17
- 23
- closed
- false
- error
- null
- Buffer contents
10 -2 5
- Required result
- lines
- 0"10"
- 1"-2"
- 2"5"
- 3""
- values
- 010
- 1-2
- 25
- closed
- false
- error
- null
- Buffer contents
""
- Required result
- lines
- 0""
- values
[]
- closed
- false
- error
- null
Try a fresh construction
This clears this draft, including its undo history. Earlier successful attempts stay recorded. Build again without opening hints to record an independent attempt.
Stuck? Inspect a worked construction
The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.
Assumptions and test precision
This local buffer model carries an error outcome to the closing piece. Python challenges exercise actual exceptions and with statements. No file is opened by this workshop. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.
Your last tested pieces can start the full construction. An existing draft there keeps its own pieces.
The Failure Happens Later
This check uses the pieces from “Read, then Close on Either Result”.
BOTIE
- Buffer contents
4 7 9 unknown
Saving your prediction runs your current construction on these inputs and checks the earlier examples too.
Build a construction in the workspace above first. This case will test those pieces.
Why does a correct total on the first example tell us little about closing after failure?
Check the resource state on both paths.
This local buffer model carries an error outcome to the closing piece. Python challenges exercise actual exceptions and with statements. No file is opened by this workshop.