[Cython] Propagating exceptions with functions which returns void*
Daniele Pianu
muogoro at gmail.com
Tue Feb 3 11:46:52 CET 2009
The function is a cdef extension type's method. Here the part of the
implementation which raises the exceptions:
cdef void *getItem( self, int i ) except NULL:
cdef void* tmpPtr
# Check NULL pointer
if self.rawPtr == NULL:
raise ValueError( "Null pointer" )
# Check specified index
if i < 0:
raise IndexError( "Unvalid index" )
# Bound checking
if self._layout[0] > 0 and i >= self._layout[0]:
raise IndexError( "Index out of bounds" )
# Code used for get the i-th value
.......
self.rawPtr is the void pointer stored by the extension type.
self._layout is a simple tuple which defines the "shape" of
self.rawPtr, used for bounds checking. The function is called by other
extension types which extend the extension type which defines the
getItem method. What do you main with "The "except NULL" is for
propagating within-Cython exceptions"? Do I need to put the getItem
call in a try-except block in the cython caller?
Daniele
2009/2/3 Dag Sverre Seljebotn <dagss at student.matnat.uio.no>:
> Daniele Pianu wrote:
>> Probably I've not completely understood the C-function
>> exception-propagating mechanism. I've a function with a prototype like
>> this
>>
>> void* getItem( void* self, int i )
>>
> Where is this function declared? What kind of exception is raised? C has
> no exceptions, and C++ exception needs a different form of declaration:
> *http://docs.cython.org/docs/pyrex_differences.html#c-exception-handling*
>
> The "except NULL" is for propagating within-Cython exceptions, see
> http://docs.cython.org/docs/language_basics.html#error-return-values
>
> Is this the reason for your problem? I might be missing the mark here.
>
> Dag Sverre
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev
>
More information about the Cython-dev
mailing list