8

I am embedding a c++ library (binding done with SIP) in my python application. Under certain circonstances (error cases), this library uses exit(), which causes my entire application to exit. Is there a way to catch this event, or do I need to modify the library to handle error cases differently ?

Thank you very much,

2
  • 5
    exit()? In a library? Somebody needs to be spanked. Commented Sep 17, 2009 at 15:35
  • FWIW: The Google test library apparently has implemented a means of circumventing exit() calls. In unit tests, you can test for program exit using the ASSERT_EXIT macro. See gtest Advanced Guide Commented Nov 19, 2012 at 11:45

2 Answers 2

7

You must modify the source of the library. There is no "exception handling" in C and exit() does not return to the calling code under any circumstances.

Sign up to request clarification or add additional context in comments.

2 Comments

+1. For some cases atexit() may help, but not if one needs to return to the calling code.
Thank you, no I am sure of what I have to do ! Rgds,
0

You can override the library linking with LD_LIBRARY_PATH and make your own exit function. Works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.