@@ -400,8 +400,61 @@ Querying the error indicator
400
400
recursively in subtuples) are searched for a match.
401
401
402
402
403
+ .. c:function:: PyObject *PyErr_GetRaisedException(void)
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`.
408
+
409
+ .. note::
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.::
413
+
414
+ {
415
+ PyObject *exc = PyErr_GetRaisedException();
416
+
417
+ /* ... code that might produce other errors ... */
418
+
419
+ PyErr_SetRaisedException (exc);
420
+ }
421
+
422
+ .. versionadded :: 3.12
423
+
424
+
425
+ .. c :function :: void PyErr_SetRaisedException (PyObject *exc)
426
+
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.)
436
+
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 ... */
447
+
448
+ PyErr_SetRaisedException (exc);
449
+ }
450
+
451
+ .. versionadded :: 3.12
452
+
453
+
403
454
.. c :function :: void PyErr_Fetch (PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
404
455
456
+ As of 3.12, this function is deprecated. Use :c:func: `PyErr_GetRaisedException ` instead.
457
+
405
458
Retrieve the error indicator into three variables whose addresses are passed.
406
459
If the error indicator is not set, set all three variables to ``NULL ``. If it is
407
460
set, it will be cleared and you own a reference to each object retrieved. The
@@ -421,10 +474,14 @@ Querying the error indicator
421
474
PyErr_Restore(type, value, traceback);
422
475
}
423
476
477
+ .. deprecated :: 3.12
478
+
424
479
425
480
.. c :function :: void PyErr_Restore (PyObject *type, PyObject *value, PyObject *traceback)
426
481
427
- Set the error indicator from the three objects. If the error indicator is
482
+ As of 3.12, this function is deprecated. Use :c:func: `PyErr_SetRaisedException ` instead.
483
+
484
+ Set the error indicator from the three objects. If the error indicator is
428
485
already set, it is cleared first. If the objects are ``NULL ``, the error
429
486
indicator is cleared. Do not pass a ``NULL `` type and non-``NULL `` value or
430
487
traceback. The exception type should be a class. Do not pass an invalid
@@ -440,9 +497,15 @@ Querying the error indicator
440
497
error indicator temporarily. Use :c:func:`PyErr_Fetch` to save the current
441
498
error indicator.
442
499
500
+ .. deprecated:: 3.12
501
+
443
502
444
503
.. c:function:: void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
445
504
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.
508
+
446
509
Under certain circumstances, the values returned by :c:func: `PyErr_Fetch ` below
447
510
can be "unnormalized", meaning that ``*exc `` is a class object but ``*val `` is
448
511
not an instance of the same class. This function can be used to instantiate
@@ -459,6 +522,8 @@ Querying the error indicator
459
522
PyException_SetTraceback(val, tb);
460
523
}
461
524
525
+ .. deprecated :: 3.12
526
+
462
527
463
528
.. c :function :: PyObject* PyErr_GetHandledException (void)
464
529
@@ -704,6 +769,18 @@ Exception Objects
704
769
:attr: `__suppress_context__ ` is implicitly set to ``True `` by this function.
705
770
706
771
772
+ .. c :function :: PyObject* PyException_GetArgs (PyObject *ex)
773
+
774
+ Return args of the given exception as a new reference,
775
+ as accessible from Python through :attr: `args `.
776
+
777
+
778
+ .. c :function :: void PyException_SetArgs (PyObject *ex, PyObject *args)
779
+
780
+ Set the args of the given exception,
781
+ as accessible from Python through :attr: `args `.
782
+
783
+
707
784
.. _unicodeexceptions :
708
785
709
786
Unicode Exception Objects
0 commit comments