@@ -402,51 +402,36 @@ Querying the error indicator
402
402
403
403
.. c:function:: PyObject *PyErr_GetRaisedException(void)
404
404
405
- Returns the exception currently being raised, clearing the exception at
406
- the same time. Do not confuse this with the exception currently being
407
- handled which can be accessed with :c:func:`PyErr_GetHandledException`.
405
+ Return the exception currently being raised, clearing the error indicator at
406
+ the same time.
408
407
409
- .. note::
408
+ This function is used by code that needs to catch exceptions,
409
+ or code that needs to save and restore the error indicator temporarily.
410
410
411
- This function is normally only used by code that needs to catch exceptions or
412
- by code that needs to save and restore the error indicator temporarily, e.g.::
411
+ For example::
413
412
414
- {
415
- PyObject *exc = PyErr_GetRaisedException();
413
+ {
414
+ PyObject *exc = PyErr_GetRaisedException();
416
415
417
- /* ... code that might produce other errors ... */
416
+ /* ... code that might produce other errors ... */
418
417
419
- PyErr_SetRaisedException (exc);
420
- }
418
+ PyErr_SetRaisedException (exc);
419
+ }
420
+
421
+ .. seealso :: :c:func:`PyErr_GetHandledException`,
422
+ to save the exception currently being handled.
421
423
422
424
.. versionadded :: 3.12
423
425
424
426
425
427
.. c :function :: void PyErr_SetRaisedException (PyObject *exc)
426
428
427
- Sets the exception currently being raised ``exc ``.
428
- If the exception is already set, it is cleared first.
429
-
430
- ``exc `` must be a valid exception.
431
- (Violating this rules will cause subtle problems later.)
432
- This call consumes a reference to the ``exc`` object: you must own a
433
- reference to that object before the call and after the call you no longer own
434
- that reference.
435
- (If you don't understand this, don't use this function. I warned you.)
429
+ Set *exc * as the exception currently being raised,
430
+ clearing the existing exception if one is set.
436
431
437
- .. note::
438
-
439
- This function is normally only used by code that needs to save and restore the
440
- error indicator temporarily. Use :c:func:`PyErr_GetRaisedException` to save
441
- the current exception, e.g.::
442
-
443
- {
444
- PyObject *exc = PyErr_GetRaisedException();
445
-
446
- /* ... code that might produce other errors ... */
432
+ .. warning ::
447
433
448
- PyErr_SetRaisedException (exc);
449
- }
434
+ This call steals a reference to *exc *, which must be a valid exception.
450
435
451
436
.. versionadded :: 3.12
452
437
0 commit comments