16

The title is pretty self explanatory -- what's the difference between:

raise Exception, "foo"

and

raise Exception("foo")

Does it do exactly the same thing, just different syntax?

I'm using Python 2.x, but I'd like to hear of any differences in Python 3.x

bradley.ayers
  • 33,409
  • 13
  • 84
  • 94
  • When you tried it, what did you observe? – S.Lott Jun 23 '11 at 01:21
  • @bradley.ayers: Okay. So what's the question, then? – S.Lott Jun 23 '11 at 01:37
  • 6
    I don't assume that because I see no discernible difference, that there *is* no difference. I think my question is fairly clear, which part are you having trouble understanding? – bradley.ayers Jun 23 '11 at 01:40
  • @bradley.ayers: If you checked `dir()` and `type()` and saw no differences, it's hard for me to imagine what difference you were hoping might secretly be hidden somewhere. Can you explain what secret, mysterious or hidden difference you think might exist. I'm sorry that I do not share your pessimism about this, but I can't understand what cryptic differences might possibly exist when the two constructs appear the same. Can you provide an example of two things which appear the same but aren't the same? – S.Lott Jun 23 '11 at 09:49
  • 2
    Perhaps the difference between ABC://google.com and abc://google.com both work fine, but the former is incorrect according to http://www.ietf.org/rfc/rfc2396.txt (Section 3.1) -- however note that it suggests programs should treat them as equivalent. In this sense for all intents and purposes they *seem* the same, but there *is* a difference, one violates the RFC, and the other doesn't. – bradley.ayers Jun 23 '11 at 10:31
  • @bradley.ayers: Since both work in Python, neither violates the Python syntax. I'm still unclear on what you're asking for. Do you want someone to check PEP8 for you? – S.Lott Jun 23 '11 at 11:09
  • 2
    You should be able to see that someone's already answered this question. I have accepted that answer, and so by reading that answer you will be able to see what I considered to be a satisfactory answer. – bradley.ayers Jun 23 '11 at 11:13
  • @bradley.ayers: Sorry. I'm unable to discern what you didn't know and how that provided the information you lacked. – S.Lott Jun 23 '11 at 11:55
  • http://stackoverflow.com/questions/336859/javascript-var-functionname-function-vs-function-functionname is another good example – bradley.ayers Jul 03 '11 at 03:06

1 Answers1

24

both amount to the same thing in Python2. in Python3, the raise Exception, "foo" syntax is no longer supported.

jcomeau_ictx
  • 35,098
  • 6
  • 89
  • 99