Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. catching a crashing call to a third party api

catching a crashing call to a third party api

Scheduled Pinned Locked Moved C / C++ / MFC
helpjsonquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jerome Conus
    wrote on last edited by
    #1

    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

    X K S 3 Replies Last reply
    0
    • J Jerome Conus

      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

      X Offline
      X Offline
      Xing Chen
      wrote on last edited by
      #2

      __try { api_call(mydata); } __except ( expression ) { // exception handler code }

      J 1 Reply Last reply
      0
      • J Jerome Conus

        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

        K Offline
        K Offline
        kakan
        wrote on last edited by
        #3

        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...

        J 1 Reply Last reply
        0
        • K kakan

          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...

          J Offline
          J Offline
          Jerome Conus
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • X Xing Chen

            __try { api_call(mydata); } __except ( expression ) { // exception handler code }

            J Offline
            J Offline
            Jerome Conus
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • J Jerome Conus

              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

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups