2

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 1

3

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')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.