Error handling in C

asked 2013-04-22 10:29:16 -0500

riothamus gravatar image

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?

edit retag flag offensive close merge delete

Comments

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.

unxnut gravatar imageunxnut ( 2013-04-22 13:12:23 -0500 )edit

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.

riothamus gravatar imageriothamus ( 2013-04-22 19:56:36 -0500 )edit

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.

unxnut gravatar imageunxnut ( 2013-04-22 21:09:07 -0500 )edit

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.

riothamus gravatar imageriothamus ( 2013-04-29 15:46:17 -0500 )edit