I’m making a C++ program. In my program I have a function with an complex algorith that fails almost 50% of the times that I run it. The error crash my program and I have to run the program again. Is totally imposible for me change this function because is an external library, so, I can’t change the code of this function.
Is there any way to manage that, when I call this function, if I get one critical error I can call again to the function and my program can continue running?
I mean, something like an exception, but this function doesn’t throw any exception. Maybe can exist in C++ one default exception when a function crash and I don’t know this.
Any idea can help me a lot. Thank you
Edit: This is the code:
#include AGraphT.h
int main(){
drawGraph();
return 0;
}
And this is the error when the program crash (I know that this error is a problem of xcb that I can not solve):
[xcb] Unknown sequence number while processing queue
As not all exceptions can be handled elegantly, and the function doesn’t throw an exception you can catch, the only option I see is to start a separate process from your main one, execute the function call on the secondary process, and retrieve the result from it. Unless it fails, in which case you start a new process.
But the sanest advice I can give is to use a different library or implement the function yourself. If I had an external function that fails 50% of the time, I wouldn’t trust the algorithm either.