raise statement

The statement that signals an error by creating and throwing an exception, as in raise ValueError("width must be positive").

In more detail

A function that cannot do its job should raise rather than return a misleading value; the caller decides how to handle it. A bare raise inside an except block re-raises the current exception after you have done some handling. Choose the built-in exception that fits: ValueError for a bad value, TypeError for a wrong type.

Related terms

Taught in

References

Certification courses