c++-Exception-Handling when using the jpeglib
Hi!
Could anyone provide a solution for my problem:
I use the (C-written) jpeglib and I want to provide my own error
handler, implemented with try/catch. I don't have any idea why it
doesn't work. After I read the documentation of the library, lngjmp
and setjmp are proposed to handle errors properly. MSDN says: "DO not
use setjmp/lngjmp" within c++-applications. So I tried the following:
- Wrote a class with a static function "static void ErrorHandler"
which throws an Error-code whenever something goes wrong within the
jpeglib.
- the jpeg-struct has a function-pointer to the error handler (called
"jerr"). So, when writing my c++-app. I mapped the functionpointer to
my own static function:
suJpegStruct->jerr = MyClass::ErrorHandler;
The class looks like this:
const int ERR_JPEG = -123456;
class CTest
{
public:
static void ErrorHandler()
{
throw ERR_JPEG;
}
void Proceed()
{
[...]
suJpegStruct->ErrorHandler;
try
{
// Jpeg-Stuff
}
catch(int lError_e)
{
// Error-handler
}
};
The Problem is: when an error comes up, my code walks straight into
the ErrorHandler (checked with a printout "In Errorhandler") but then,
after the exception has been thrown, never goes back to the catch-
branch.
Does anyone have a better idea or even a solution, what I did wrong?
Thanks in advance for your help,
Frank
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]