[Numpy-discussion] stderr

Charles R Harris charlesr.harris@gmail....
Sat Jun 27 14:38:14 CDT 2009


On Sat, Jun 27, 2009 at 1:12 PM, Pauli Virtanen <pav@iki.fi> wrote:

> On 2009-06-27, Charles R Harris <charlesr.harris@gmail.com> wrote:
> [clip]
> >
> >    PyOS_snprintf(format, sizeof(format), _FMT1, prec);
> >    res = NumPyOS_ascii_format@type@(buf, buflen, format, val, 0);
> >    if (res == NULL) {
> >        fprintf(stderr, "Error while formatting\n");
> >        return;
> >    }
> >
> [clip]
> > Do we want to raise an error here? Alternatively, we could use an assert.
>
> I'd advise against asserts. They should be used only for
> conditions that are (expected to be) logically impossible. This
> one here seems to be possible when out-of-memory, or some other
> condition.
>
> Also, an assert makes the program crash on C-level, which is
> clearly undesirable in a Python program as it cannot be handled.
>
> Raising an error here seems to be the proper thing to do.
>

I'm inclined that way also, but it will require some work. The routine
currently returns nothing so the calling routine will need to call into
python to see if an error was raised. Alternatively, we could add an error
return.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090627/1bd6ce14/attachment.html 


More information about the Numpy-discussion mailing list