In programming, exceptions are unexpected events that happen while a program is running, usually due to an error condition or an unanticipated inputs. Object-oriented languages abstract exceptions as objects.

Exceptions also occur on the hardware level as interrupts.

Raising exceptions

Sometimes it makes sense for us to raise our own exceptions in our code. This is especially useful if we’re writing a library or a function that others will use.

In Python, given an invalid input, we can raise an error pretty easily:

raise ValueError('Error message') # swap out error type as needed