@@ -402,58 +402,45 @@ 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 ::
432
+ .. warning ::
438
433
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 ... */
447
-
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
453
438
454
439
.. c :function :: void PyErr_Fetch (PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
455
440
456
- As of 3.12, this function is deprecated. Use :c:func: `PyErr_GetRaisedException ` instead.
441
+ .. deprecated :: 3.12
442
+
443
+ Use :c:func: `PyErr_GetRaisedException ` instead.
457
444
458
445
Retrieve the error indicator into three variables whose addresses are passed.
459
446
If the error indicator is not set, set all three variables to ``NULL ``. If it is
@@ -462,8 +449,10 @@ Querying the error indicator
462
449
463
450
.. note ::
464
451
465
- This function is normally only used by code that needs to catch exceptions or
466
- by code that needs to save and restore the error indicator temporarily, e.g.::
452
+ This function is normally only used by legacy code that needs to catch
453
+ exceptions or save and restore the error indicator temporarily.
454
+
455
+ For example::
467
456
468
457
{
469
458
PyObject *type, *value, *traceback;
@@ -474,15 +463,17 @@ Querying the error indicator
474
463
PyErr_Restore(type, value, traceback);
475
464
}
476
465
477
- .. deprecated :: 3.12
478
-
479
466
480
467
.. c :function :: void PyErr_Restore (PyObject *type, PyObject *value, PyObject *traceback)
481
468
482
- As of 3.12, this function is deprecated. Use :c:func: `PyErr_SetRaisedException ` instead.
469
+ .. deprecated :: 3.12
470
+
471
+ Use :c:func: `PyErr_SetRaisedException ` instead.
483
472
484
- Set the error indicator from the three objects. If the error indicator is
485
- already set, it is cleared first. If the objects are ``NULL ``, the error
473
+ Set the error indicator from the three objects,
474
+ *type *, *value *, and *traceback *,
475
+ clearing the existing exception if one is set.
476
+ If the objects are ``NULL ``, the error
486
477
indicator is cleared. Do not pass a ``NULL `` type and non-``NULL `` value or
487
478
traceback. The exception type should be a class. Do not pass an invalid
488
479
exception type or value. (Violating these rules will cause subtle problems
@@ -493,18 +484,17 @@ Querying the error indicator
493
484
494
485
.. note::
495
486
496
- This function is normally only used by code that needs to save and restore the
497
- error indicator temporarily. Use :c:func:`PyErr_Fetch` to save the current
498
- error indicator.
499
-
500
- .. deprecated:: 3.12
487
+ This function is normally only used by legacy code that needs to
488
+ save and restore the error indicator temporarily.
489
+ Use :c:func:`PyErr_Fetch` to save the current error indicator.
501
490
502
491
503
492
.. c:function:: void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
504
493
505
- As of 3.12, this function is deprecated.
506
- Use :c:func: `PyErr_GetRaisedException ` instead of :c:func: `PyErr_Fetch ` to avoid
507
- any possible de-normalization.
494
+ .. deprecated :: 3.12
495
+
496
+ Use :c:func: `PyErr_GetRaisedException ` instead,
497
+ to avoid any possible de-normalization.
508
498
509
499
Under certain circumstances, the values returned by :c:func: `PyErr_Fetch ` below
510
500
can be "unnormalized", meaning that ``*exc `` is a class object but ``*val `` is
@@ -522,8 +512,6 @@ Querying the error indicator
522
512
PyException_SetTraceback(val, tb);
523
513
}
524
514
525
- .. deprecated :: 3.12
526
-
527
515
528
516
.. c :function :: PyObject* PyErr_GetHandledException (void)
529
517
@@ -771,14 +759,12 @@ Exception Objects
771
759
772
760
.. c :function :: PyObject* PyException_GetArgs (PyObject *ex)
773
761
774
- Return args of the given exception as a new reference,
775
- as accessible from Python through :attr: `args `.
762
+ Return :attr: `~BaseException.args ` of exception *ex *.
776
763
777
764
778
765
.. c :function :: void PyException_SetArgs (PyObject *ex, PyObject *args)
779
766
780
- Set the args of the given exception,
781
- as accessible from Python through :attr: `args `.
767
+ Set :attr: `~BaseException.args ` of exception *ex * to *args *.
782
768
783
769
784
770
.. _unicodeexceptions :
0 commit comments