raise Exception or raise Exception()

E

ernest

I have seen both forms and I'm not sure if they're
both correct, or one is right and the other wrong.
In practical terms, the two of them seem to have
the same effect.

Cheers,
Ernest
 
C

Chris Rebert

I have seen both forms and I'm not sure if they're
both correct, or one is right and the other wrong.

They're both acceptable (although obviously you should always raise a
more specific error than Exception).
`raise SomeException` is in fact equivalent to `raise SomeException()`.
Providing an error message is always advisable though, so really in
most cases you ought to `raise SomeException("Informative error
message")`

Cheers,
Chris
 
R

Roy Smith

Chris Rebert said:
They're both acceptable (although obviously you should always raise a
more specific error than Exception).
`raise SomeException` is in fact equivalent to `raise SomeException()`.

I've always found this rather disconcerting and unpythonic. Sure, it
saves a couple of keystrokes here and there, but it also adds confusion
such as Ernest's. It reminds me of Perl's letting you omit the
parentheses on function calls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top