Edited:
(This post has been largely edited compared to its previous version).
For test purpose I have a module, say, ptest.py :
# ptest.py
def testfunc(*args) :
# Some process that can take significant time. There may be some integers larger than 2^64.
After cythonizing it to, say, ctest.pyx I got an increase in performance with some further tests (as expected).
Now for some integer value large enough the program may throw OverflowError while in pure python that might not happen. In this case, can I raise SomeError with information (say, ValueError('The number should not be greater than some value')) in cython as we do in python ?
Even I did the same,
if n > 2**64:
raise ValueError("Number should be a non negative integer less than 2^64.")
it kept showing: OverflowError: Python int too large to convert to C unsigned long. Seems to ignore the condition completely.
So, how can I inform the user ? And finally, can I use cython in pure python without cythonizing the entire program (that is without setup, build etc.) as I don't want to lose those functionality of python (in this case raising Exception, handling sufficiently large integer etc.)?
I tried other methods from cython module (following Cython doc.) like, cython.declare, cython.exceptval etc. in .py file but they all seem to be a failure in improving the performance. I haven't approached ctypes yet as I want the proper technique beforehand.