libjpeg error handling
I'm writing a gtk-- program (so, signal-slot mechanism) to handle jpeg images and something else.
The problem now is that i want to catch errors from libjpeg not to have the exit() called, for example:
The users click: File->Open New Jpeg->
And he clicks on a non-jpeg file: the befault behaviour for libjpeg is to write something like
"not a jpeg file" and call exit().
The libjpeg docs say:
"
Error handling
--------------
When the default error handler is used, any error detected inside the JPEG
routines will cause a message to be printed on stderr, followed by exit().
You can supply your own error handling routines to override this behavior
and to control the treatment of nonfatal warnings and trace/debug messages.
The file example.c illustrates the most common case, which is to have the
application regain control after an error rather than exiting.
The JPEG library never writes any message directly; it always goes through
the error handling routines. Three classes of messages are recognized:
* Fatal errors: the library cannot continue.
* Warnings: the library can continue, but the data is corrupt, and a
damaged output image is likely to result.
* Trace/informational messages. These come with a trace level indicating
the importance of the message; you can control the verbosity of the
program by adjusting the maximum trace level that will be displayed.
.... you can override functions ....
The individual methods that you might wish to override are:
error_exit (j_common_ptr cinfo)
Receives control for a fatal error. Information sufficient to
generate the error message has been stored in cinfo->err; call
output_message to display it. Control must NOT return to the caller;
generally this routine will exit() or longjmp() somewhere.
Typically you would override this routine to get rid of the exit()
default behavior. Note that if you continue processing, you should
clean up the JPEG object with jpeg_abort() or jpeg_destroy().
".
I have done that, in the sense that i see my little MyErrorExit() function writing "hello! i'm here" but, after doing something, the control returns to the caller, and it exit() or start looping, depending to what i 've done inside MyErrorExit() (later if you want i can paste it)
Any ideas??
Thanks
Luigi
__
|