Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bb99210

Browse files
committed
Review edits of exceptions.rst
1 parent c2c3d1d commit bb99210

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

‎doc/sphinx/source/exceptions.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ These CPython calls are the most useful:
2525
`PyErr_Occurred() documentation <https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Occurred>`_
2626
* ``PyErr_Clear()`` - Clearing any set exceptions, have good reason to do this!
2727
`PyErr_Clear() documentation <https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Clear>`_
28+
* ``PyErr_Print()`` - Print a representation of the current exception then clear any set exceptions.
29+
`PyErr_Print() documentation <https://docs.python.org/3.13/c-api/exceptions.html#c.PyErr_Print>`_
2830

2931
Indicating an error condition is a two stage process; your code must register an exception and then indicate failure
3032
by returning ``NULL``. Here is a C function doing just that:
@@ -169,9 +171,10 @@ The following C code is equivalent to the Python code:
169171
class SpecialisedError(ExceptionBase):
170172
pass
171173
172-
This can be done quite easily using either the ``PyErr_NewException`` or the ``PyErr_NewExceptionWithDoc`` functions.
173-
These create new exception classes that can be added to a module.
174-
For example:
174+
Declaring Specialised Exceptions
175+
---------------------------------
176+
177+
Firstly declare the ``PyObject *`` exception:
175178

176179
.. code-block:: c
177180
@@ -182,6 +185,11 @@ For example:
182185
183186
/* NOTE: Functions that might raise one of these exceptions will go here. See below. */
184187
188+
189+
190+
Example Module
191+
-----------------------------------
192+
185193
Now define the module, ``cExceptions_methods`` is explained later:
186194

187195
.. code-block:: c
@@ -195,7 +203,12 @@ Now define the module, ``cExceptions_methods`` is explained later:
195203
NULL, NULL, NULL, NULL,
196204
};
197205
198-
Initialise the module, this registers the exception types and the class hierarchy:
206+
Initialising Specialised Exceptions
207+
-----------------------------------
208+
209+
This can be done quite easily using either the ``PyErr_NewException`` or the ``PyErr_NewExceptionWithDoc`` functions.
210+
These create new exception classes that can be added to a module.
211+
For example, initialise the module, this registers the exception types and the class hierarchy:
199212

200213
.. code-block:: c
201214
@@ -246,6 +259,9 @@ Initialise the module, this registers the exception types and the class hierarch
246259
return m;
247260
}
248261
262+
Raising Specialise Exceptions
263+
-----------------------------
264+
249265
To illustrate how you raise one of these exceptions suppose we have a function to test raising one of these exceptions:
250266

251267
.. code-block:: c

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /