effectivepython icon indicating copy to clipboard operation
effectivepython copied to clipboard

Item #20: Extra "as e" in except statement

Open bslatkin opened this issue 5 years ago • 0 comments

Page 82, Item 20, line 11 from top

try:
    return a / b
except ZeroDivisionError as e:
    raise ValueError('Invalid inputs')

The "as e" isn't necessary anymore because of the chaining automatically enabled by __cause__ and __context__:

https://docs.python.org/3/library/exceptions.html

bslatkin avatar Nov 12 '19 17:11 bslatkin