Exceptions

Published

2023-07-31

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:

  1. 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.

  2. 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.

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

This material is for free use under either the GNU Free Documentation License or the Creative Commons Attribution-ShareAlike 3.0 United States License (take your pick).