May 2019
Beginner
528 pages
29h 51m
English
You’ve seen various exceptions raised by your Python code. Sometimes you might need to write functions that raise exceptions to inform callers of errors that occur. The raise statement explicitly raises an exception. The simplest form of the raise statement is
raise ExceptionClassName
The raise statement creates an object of the specified exception class. Optionally, the exception class name may be followed by parentheses containing arguments to initialize the exception object—typically to provide a custom error message string. Code that raises an exception first should release any resources acquired before the exception occurred. In the next section, we’ll show an example of raising an exception.
In most ...
Read now
Unlock full access