Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FUNCTIONS / CHAPTER 04 / Learn / LESSON 07
Seventh class. Sometimes you must signal an error with a clear message: raise ValueError("n must be positive").
def require_positive(n): if n <= 0: raise ValueError("n must be positive") return n
The caller can catch it with try/except and print the message. A good message says what went wrong.
Common mistake: raise without useful text; or catching everything and staying silent.
Learn: raise signals an error with text.
STREAM IDLE
›