catching a crashing call to a third party api
-
Hi ! In my application, I'm making a call to a function provided by a third party library. Unfortunately, this call is crashing in some situations (which I have no way to detect prior to calling the function). I tried to put the call into a try{} catch{} block, but it didn't work. Here is what I did : try { api_call(mydata); } catch (...) { // error } the problem is that my app keeps crashing in the 'try' block, which is something I don't understand. I'm compiling with expection support. Any hint ? Thanks ! Jerome
-
Hi ! In my application, I'm making a call to a function provided by a third party library. Unfortunately, this call is crashing in some situations (which I have no way to detect prior to calling the function). I tried to put the call into a try{} catch{} block, but it didn't work. Here is what I did : try { api_call(mydata); } catch (...) { // error } the problem is that my app keeps crashing in the 'try' block, which is something I don't understand. I'm compiling with expection support. Any hint ? Thanks ! Jerome
-
Hi ! In my application, I'm making a call to a function provided by a third party library. Unfortunately, this call is crashing in some situations (which I have no way to detect prior to calling the function). I tried to put the call into a try{} catch{} block, but it didn't work. Here is what I did : try { api_call(mydata); } catch (...) { // error } the problem is that my app keeps crashing in the 'try' block, which is something I don't understand. I'm compiling with expection support. Any hint ? Thanks ! Jerome
You could give more information, here is my guess. If you are calling a C-function from a C++-class, you have to do this in the third party .h-file: Surround all function declarations with this code: #ifdef __cplusplus extern "C" { #endif // the original function prototypes #ifdef __cplusplus } #endif Else, the first parameter of all function calls will be the this pointer. And that will make the funcion call to crash...
-
You could give more information, here is my guess. If you are calling a C-function from a C++-class, you have to do this in the third party .h-file: Surround all function declarations with this code: #ifdef __cplusplus extern "C" { #endif // the original function prototypes #ifdef __cplusplus } #endif Else, the first parameter of all function calls will be the this pointer. And that will make the funcion call to crash...
Hi thanks for your answer. I'm actually calling a C++ function from a C++ class. The call to the function works in most cases, but crashes in some specific cases. Jerome
-
Hi ! Thanks for your answer, but it seems __try and __except are MS specific keyword. I'm compiling in a linux environnement... Any onther hint ? Thanks ! Jerome
-
Hi ! In my application, I'm making a call to a function provided by a third party library. Unfortunately, this call is crashing in some situations (which I have no way to detect prior to calling the function). I tried to put the call into a try{} catch{} block, but it didn't work. Here is what I did : try { api_call(mydata); } catch (...) { // error } the problem is that my app keeps crashing in the 'try' block, which is something I don't understand. I'm compiling with expection support. Any hint ? Thanks ! Jerome
Chenxing's solution will work - As much as catching an unexpected exception will ever work. Here's how to do it:
__try { api_call(mydata); } __except(EXCEPTION_EXECUTE_HANDLER) { // Error! }
Note that catching an unexpected exception is never a good idea - For example the exception might have occurred while a node was being linked into a linked list but has only been half linked in. Or perhaps after a
CRITICAL_SECTION
was entered but before it is released. Once an unexpected exception occurs the state of the application is suspect. I realize you may have no choice but nethertheless beware - You may end up creating more problems for yourself. Steve I just noticed the comment where you said you're programming on Linux - Sorry. -- modified at 4:22 Friday 10th March, 2006