8000 Merge pull request #4185 from caternuson/doc_update · alexbartlow/circuitpython@766e79a · GitHub
[go: up one dir, main page]

Skip to content

Commit 766e79a

Browse files
authored
Merge pull request adafruit#4185 from caternuson/doc_update
Design Guide Update - Exception and asserts
2 parents 9aecbd6 + ac6695f commit 766e79a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/design_guide.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ use what.
165165
Here is more info on properties from
166166
`Python <https://docs.python.org/3/library/functions.html#property>`_.
167167

168+
Exceptions and asserts
169+
--------------------------------------------------------------------------------
170+
171+
Raise an appropriate `Exception <https://docs.python.org/3/library/exceptions.html#bltin-exceptions>`_,
172+
along with a useful message, whenever a critical test or other condition fails.
173+
174+
Example::
175+
176+
if not 0 <= pin <= 7:
177+
raise ValueError("Pin number must be 0-7.")
178+
179+
If memory is constrained and a more compact method is needed, use `assert`
180+
instead.
181+
182+
Example::
183+
184+
assert 0 <= pin <= 7, "Pin number must be 0-7."
185+
168186
Design for compatibility with CPython
169187
--------------------------------------------------------------------------------
170188

0 commit comments

Comments
 (0)
0