[go: up one dir, main page]

File: errors.rst

package info (click to toggle)
cppy 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: cpp: 390; python: 86; ansic: 62; makefile: 13
file content (37 lines) | stat: -rw-r--r-- 982 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Error reporting
===============

In addition to `cppy::ptr`, cppy provides a set of convenience functions for
reporting errors which all return a NULL pointer allowing them to be used as
follows:

.. code:: c++

    PyObject* function( PyObject* obj )
    {
        cppy::ptr obj_ptr( cppy::incref( obj ) );
        if( !obj_ptr.is_bool() )
            return type_error( obj_ptr.get(), "bool" );
        return obj_ptr.get();
    }

Functions
---------

Functions taking two arguments provide sensible pre-formatted error messages.

.. code:: c++

    inline PyObject* system_error( const char* message )

    inline PyObject* type_error( const char* message )

    inline PyObject* type_error( PyObject* ob, const char* expected )

    inline PyObject* value_error( const char* message )

    inline PyObject* runtime_error( const char* message )

    inline PyObject* attribute_error( const char* message )

    inline PyObject* attribute_error( PyObject* ob, const char* attr )