From: Joerg H. <jo...@de...> - 2004-05-18 11:51:19
|
On Tue, May 18, 2004 at 07:20:07AM +0200, Lutz Müller wrote: > > > Why do I have to return a struct when no error occurred? > > I thought about something like that: > > int > main (...) { > int i1, i2; > ExifError e = {0, ""}; > > /* Calling a function without error checking */ > exif_function (i1, i2, NULL); > > /* Calling a function with error checking */ > exif_function (i1, i2, &e); > if (e.id != 0) > printf ("Error %i occurred: %s.\n", e.id, e.msg); > } That would be much work to do; I think at this moment it would be easier to work with return values. The errors I want to catch with this approach are relativly "simple" errors like error return values of libc-calls (malloc, realloc) and possibly invalid (NULL) arguments. Look at the points in functions where at this moment we just do a simple "return". Most times it's enough to distinct between "error occured" and "no error". There we don't need a highly-sophisticated concept how we want to do our error handling. We just need to detect them. On higher levels a solution like your proposal would be ok, but on the bottom level it's kind of overkill. Joerg -- Fachbegriffe der Informatik (Nr 68): WWW - World Wide Waiting |