I am using the C++ JPEG library (libjpeg) and I have realized that when some functions fail exit() is called and the application is closed. How can I override this behavior and prevent the application from closing on libjpeg errors?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Using c++11 I implemented this using a lambda (similar to Marco's answer):
which works well. Only then catch on 'struct jpeg_error_mgr *err'
i.e.
and
As the question was targetting C++, an alternative approach with exceptions:
Error handler:
Use it:
This is the default behavior of
libjpeg
. In order to handle errors with libjpeg, you'll have to define an error handling routine like this:And then register it using
jpeg_std_error
.You can find a complete example here.