DELAPARRA
Index
Color
NL
Category: Error types

AssertionError

Explained by Updated

What is AssertionError?

AssertionError: A sanity-check assertion in the code evaluated to false, signalling that an assumption the programmer relied on turned out to be untrue. An AssertionError is raised when an assertion in the code turns out false. An assertion states something the developer believes must always be true, such as assert total >= 0. When it fails, that belief was wrong, and the program stops.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about AssertionError

How is AssertionError used in practice?

Assertions are a tool for catching bugs early. They document assumptions and fail loudly at the exact spot where reality differs from expectations, instead of letting bad data travel further.

What should you keep in mind with AssertionError?

They are not for validating user input. In Python and PHP, assertions can be switched off in production, so a check that protects against bad input would silently disappear. Use proper validation and exceptions for anything a user or another system can cause. Keep assertions for internal logic, and in tests, where assertion failures are exactly how you learn that something broke.

At a glance

CategoryError types
Explained by
Updated

More Error types terms

All terms starting with A

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.