Style:Exceptions
From 6.00 reference wiki
Elements of Style for Python Programmers: Main | Names | Variable Declarations | Indentation | Exceptions
Functions should either raise an exception or return the special value None when there is no sensible value for them to return.
For example:
def factorial(n):
"""n: int
if n >= 0
returns n!
else returns None"""
or
def factorial(n):
"""n: int
if n >= 0
returns n!
else raises negArg"""
is better than a factorial program that returns -1 when called with a negative number.
![[Main Page]](../../../../var/www/mediawiki-1.6.3/images/eecs-logo2.png)