This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: gsl_histogram*_clone should fail silently
- From: Achim Gaedke <Achim dot Gaedke at uni-koeln dot de>
- To: Brian Gough <bjg at network-theory dot co dot uk>
- Cc: gsl discussion list <gsl-discuss at sources dot redhat dot com>
- Date: Mon, 21 Jan 2002 02:15:52 +0100
- Subject: Re: gsl_histogram*_clone should fail silently
- References: <3C4AE14C.778AC716@uni-koeln.de> <15435.12274.673538.566684@debian>
Brian Gough writes:
> Hi,
>
> The general philosophy is to use GSL_ERROR for every error condition.
> In some cases this gives multiple error messages but this "is not a
> bug, it's a feature" -- more error messages, more information. For
> example, two inconsistent error messages immediately suggests an
> uninitialized variable, which is the correct interpretation here.
>
> --
> Brian
No, this is no uninitialised variable error and one message is enough, the other
is definitely wrong.
If you think, it is right to call the handler twice, the error message should
be:
"reason: failed to copy histogram struct, several reasons possible, errno text:
input domain error"
here is the original test program output: The source can be found at the end.
[achim@localhost c]$ make
cc gsl_histogram_error.c -o gsl_histogram_error -I/opt/gsl-1.0/include
-L/opt/gsl-1.0/lib -lgsl -lgslcblas
[achim@localhost c]$ ./gsl_histogram_error d
reason: histogram bin extremes must be in increasing order, errno text: input
domain error
reason: failed to allocate space for histogram struct, errno text: malloc failed
[achim@localhost c]$ ./gsl_histogram_error
gsl: calloc_range.c:55: ERROR: histogram bin extremes must be in increasing
order
Aborted
You see both messages with the non aborting handler. But if you use the default
handler, you will only get the right message.
This problem arises, because an api function uses another api function. If one
function has called the handler, the other function should explain the error
correct or should rely on the error handling of the first one.
I do not know, if it is the same in other countries: "One (punishable) act can
be only once punished." is a basic justice rule in Germany. This is reasonable
imo .
My problem is: in pygsl (wrapper to python) the error handler sets an exception.
If the handler sets it twice, the former is lost. Ok, it might be my problem.
On the other hand the concept of exceptions is quite powerful, because the
reason of this error is sent to the right level. This could be the same with
error handlers. If it is called twice, the handler might be confused... yes, I
see, here might be no need for complicated error handling...
Source code:
#include <stdio.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_histogram.h>
void handler (const char * reason,
const char * file,
int line,
int gsl_errno) {
printf("reason: %s, errno text: %s\n",reason, gsl_strerror(gsl_errno) );
}
int main (int argc, char** argv) {
gsl_histogram* hist1=gsl_histogram_alloc(100);
gsl_histogram* hist2;
if (argc>1)
gsl_set_error_handler(handler);
hist1->range[0]=1;
hist1->range[1]=0;
hist2=gsl_histogram_clone(hist1);
return 0;
}