Objective
When you catch a low-level error and raise your own, you should chain them with raise ... from e: the new error explains what failed and __cause__ keeps the original cause.
Instructions
- The first line has the number
nof lines; each one isname value unit(the value is an integer and the unit iskbormb). - Define
ConfigError. If the line is valid, showname = byteswith the value in bytes (1KB = 1024 bytes,1MB = 1024² bytes). If not (wrong format, non-numeric value or unknown unit), raiseConfigErrorwith messageinvalid linechaining the original error, and showLine k: invalid line (cause: ErrorType).
3
cache 10 kb
disco x mb
logs 5 gb
cache = 10240
Line 2: invalid line (cause: ValueError)
Line 3: invalid line (cause: KeyError)
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise