6.8 The raise statement

raise_stmt:     "raise" [expression ["," expression ["," expression]]]

If no expressions are present, raise re-raises the last expression that was raised in the current scope.

Otherwose, raise evaluates its first expression, which must yield a string, class, or instance object. If there is a second expression, this is evaluated, else None is substituted. If the first expression is a class object, then the second expression must be an instance of that class or one of its derivatives. If the first expression is an instance object, the second expression must be None.

If the first object is a class or string, it then raises the exception identified by the first object, with the second one (or None) as its parameter. If the first object is an instance, it raises the exception identified by the class of the object, with the instance as its parameter (and there should be no second object, or the second object should be None).

If a third object is present, and it is not None, it should be a traceback object (see section 3.2), and it is substituted instead of the current location as the place where the exception occurred. This is useful to re-raise an exception transparently in an except clause.