Exceptions
Exceptions
AssertionError
As we’ve seen, if an assertion passes, code execution continues normally. However, if an assertion fails, an AssertionError
is raised. This indicates that what has been asserted has evaluated to False
.
If you write an assertion, and when you test your code an AssertionError
is raised, then you should do two things:
Make sure that the assertion you’ve written is correct. That is, you are asserting some condition is true when it should, in fact, be true.
If you’ve verified that your assertion statement(s) are correct, and an
AssertionError
continues to be raised, then it’s time to debug your code. Continue updating and testing until the issue is resolved.
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.