I need to raise an exception. In my specific case NotImplementedError.
What is the difference between
Raise NotImplementedError and raise NotImplementedError().
Which is considered a better practice? Why?
1 Answer
There is no difference between raise X and raise X(). It's better to use the second form and pass a message like raise RuntimeError('bad argument'). If there is no useful message like your case I go with first syntax. It's a matter of taste.
The first form is a remaining of old style raising (not valid in Python3):
raise X, 'a'
is the same as
raise X('a')