How to catch a usefull error message ?

Chris Angelico rosuav at gmail.com
Tue Apr 23 13:23:47 EDT 2019


On Wed, Apr 24, 2019 at 3:18 AM Vincent Vande Vyvre
<vincent.vande.vyvre at telenet.be> wrote:
>
> Hi,
>
> In a CPython lib I have an _init() method wich take one argument, a file
> name.
>
>      char *fname;
>
>      if (!PyArg_ParseTuple(args, "s", &fname))
>          return NULL;
>
> So, if I instanciate my object with a bad argument I've a good error
> message:
>
> tif = ImgProc(123)
> TypeError: argument 1 must be str, not int
> (followed by the traceback)
>
> But if I do:
> try:
>      tif = ImgProc(123)
> except Exception as why:
>      print("Error:", why)
>
> I get just:
>
> Error: <class '_liboqapy.ImgProc'> returned a result with an error set
>

It looks like there's an internal problem in the C function. Are you
sure it's hitting the PyArg_ParseTuple and then immediately returning
NULL? Post a bit more of your code; this error looks like something is
leaving an error state but then carrying on with the code.

ChrisA



More information about the Python-list mailing list