How to check if the function would generate an exit in C ++

1

I have .lib with some functions. I define that when the calculation of some function generates values outside the allowed range it gives a exit() .

Now my code in C ++ that uses this lib needs to compute some of these functions but if the function that I compute in midstream generates an exit it aborts and does not calculate the others. Is there any way to check if it returns in an exit or not, and if it returns skip the function?

I'm not sure if there would be a better flag for values outside the allowed range other than the exit . I would try to return Null; but some of these functions generate vector<double>

What would be the best way to do this?

    
asked by anonymous 29.03.2018 / 06:27

1 answer

5

There's no way. Your problem is different.

The problem is design . If you want to know if the function has succeeded in achieving your goal or do not use a form of communication that indicates this, do not use exit() . This function should be used for serious problem cases or for normal application termination at some point where the goal has been achieved and nothing else should be done.

There are several techniques to tell if the function worked or not, in your case you could use an exception, or some error returned . If nullptr does not meet, but is generally adequate, it has other forms quoted in the linked question.

Even testing whether the function will work and then using it has the potential to generate a race condition , is not the proper way.

    
29.03.2018 / 13:04