I have a hard time figuring this one out, it's about mistakes that can be done when raising an exception in Python 2.7:
try:
raise [1, 2, 3, 4]
except Exception as ex:
print ex
the message here is "exceptions must be old-style classes or derived from BaseException, not list" - This part is ok, but when I change it to tuple, I am getting confused:
try:
raise (1, 2, 3, 4)
except Exception as ex:
print ex
the message here is "exceptions must be old-style classes or derived from BaseException, not int" - why is it interpreted as raising an int, not a tuple?
Futhermore:
try:
raise (Exception, 'a message')
except Exception as ex:
print ex
Here we are actually rising an Exception (consistent behaviour when compared with previous example, where we were raising an int) - I briefly thought that this is just an alternate way for this:
try:
raise Exception, 'a message'
except Exception as ex:
print ex
But in this case, 'a message' is being passed to Exceptions ctor (as documented on docs.python.org)
Can someone explain the 2nd and 3rd cases, and possible point me to code in interpreter that is responsible for this?