This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: generator.throw() behavior
Type: behavior Stage: resolved
Components: Documentation, Interpreter Core Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: generator.throw() documentation inaccurate
View: 14911
Assigned To: docs@python Nosy List: BreamoreBoy, docs@python, ezio.melotti, flox, ncoghlan, petri.lehtinen, pitrou
Priority: normal Keywords:

Created on 2011-10-18 18:16 by petri.lehtinen, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg145848 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-10-18 18:16
The documentation of generator.throw() gives this signature:

    generator.throw(type[, value[, traceback]])

Looking at the code, it accepts the following arguments:

  g.throw(ExcType)  --> raise ExcType()

  g.throw(ExcType, None)  --> raise ExcType()

  g.throw(ExcType, None, tb)  --> raise ExcType().with_traceback(tb)

  g.throw(ExcType, instace_of_ExcType)  --> raise instance_of_ExcType

  g.throw(ExcType, instace_of_ExcType, tb)  --> raise instance_of_ExcType.with_traceback(tb)

  g.throw(ExcType, other_value)  --> raise ExcType(other_value)

  g.throw(ExcType, other_value, tb)  --> raise ExcType(other_value).with_traceback(tb)

Up to this point, I think everything is in line with the documentation. But it also accepts the following (now that issue 13188 is fixed):

  g.throw(exc_instance) --> raise exc_instance (preserving the traceback of exc_instance)

  g.throw(exc_instance, None) --> raise exc_instance (preserving the traceback of exc_instance)

  g.throw(exc_instance, None, tb) --> raise exc_instance.with_traceback(tb)

It does not accept these, throwing a TypeError:

  g.throw(exc_instance, some_value_other_than_None)
  g.throw(exc_instance, some_value_other_than_None, tb)
  g.throw(exc_instance, tb)

The documentation is really unclear on throwing existing exception instances with (exc_instance) or (exc_instance, None), and that calling with (type, value) or (type, value, tb) will create a new exception if not isinstance(value, type).
msg221584 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-25 23:49
@Petri can you propose a patch for this?
History
Date User Action Args
2022-04-11 14:57:22adminsetgithub: 57422
2015-06-20 12:02:41martin.pantersetstatus: open -> closed
superseder: generator.throw() documentation inaccurate
resolution: duplicate
stage: resolved
2014-06-25 23:49:45BreamoreBoysetnosy: + BreamoreBoy
messages: + msg221584
2011-10-18 18:48:57floxsetnosy: + flox
2011-10-18 18:16:43petri.lehtinencreate