Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raise class exception or instance of class exception when no arguments are passed

Tags:

python

I saw that sometimes there are raised classes and sometimes there are raised instances of classes.

Which way to raise exception is better if you don't want to add any additional info as arguments

raise ValueError

or

raise ValueError()

?

like image 515
scdmb Avatar asked Aug 15 '13 09:08

scdmb


1 Answers

It doesn't matter, as Python will create the instance if you only raised the class.

However, it is better to be explicit and create the instance yourself, to make it unambiguous you meant to use it without arguments.

like image 76
Martijn Pieters Avatar answered Nov 15 '22 03:11

Martijn Pieters