Error handling in C [closed]
I am developing in C using opencv 2.4.5 and need to gracefully handle run-time errors. The default behavior for opencv is to print an error and terminate the application. I'd like to not terminate the application.
In previous versions of the library, this could be changed using cvSetErrorMode
, which has been deprecated.
Given that the current error handling is done by throwing a exception in C++, how are we to gracefully handle errors in C, which does not support exceptions?
You will need to define what you mean by "gracefully handle errors". Do you want to restart the application from a certain point? Or just print a message and continue as if nothing happened. The second option will be tough but the first one is easy enough to accomplish.
I don't want to restart the application, nor continue as if nothing happened (that would be an unstable state).
A simple example would be a function that returns 1 if opencv encounters an error, and 0 otherwise.
Possibly you can write a wrapper around the code but without much knowledge of your code and application, it is hard to give a meaningful suggestion.
Writing a wrapper is possible, but I'd rather not: 1) modify opencv -or- 2) Write the software in c++
Background: I'm writing an image processing webservice in C. If opencv encounters an error, I'd like to catch it and return an appropriate response via http to the user. As opencv is currently implemented, the program terminates on error.