[Numpy-discussion] stderr

David Cournapeau cournape at gmail.com
Sun Jun 28 09:16:50 EDT 2009


On Sun, Jun 28, 2009 at 4:38 AM, Charles R
Harris<charlesr.harris at gmail.com> wrote:
>
>
> On Sat, Jun 27, 2009 at 1:12 PM, Pauli Virtanen <pav at iki.fi> wrote:
>>
>> On 2009-06-27, Charles R Harris <charlesr.harris at gmail.com> wrote:
>> [clip]
>> >
>> >    PyOS_snprintf(format, sizeof(format), _FMT1, prec);
>> >    res = NumPyOS_ascii_format at 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.

We could just raise a python exception, if this is possible (I don't
know if those format_* functions are allowed to fail).

David



More information about the NumPy-Discussion mailing list