next up previous contents index
Next: The break statement Up: Simple statements Previous: The return statement

The raise statement

  

raise_stmt:     "raise" condition ["," condition ["," condition]]

raise evaluates its first condition, which must yield a string, class, or instance object. If there is a second condition, this is evaluated, else None is substituted. If the first condition is a class object, then the second condition must be an instance of that class or one of its derivatives. If the first condition is an instance object, the second condition 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 it not None, it should be a traceback object (see section gif), 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.   



guido@cwi.nl