0

I've a PCI card (PISO Encoder 600/300) in which reads data from a sensor. In computers that the PCI card is not connected, the code crashes and I've tried to handle the exception by using try/catch but the exception didn't caught:

try {
    ENC6_REGISTRATION(0,0);
} catch (...){}

this is not working! How can I handle this exception?

Mosi
  • 1,178
  • 2
  • 12
  • 30
  • `try-catch` block does not handle SEH exceptions by default. See this: http://stackoverflow.com/questions/2782915/what-should-i-know-about-structured-exceptions-seh-in-c – Ari0nhh Apr 18 '17 at 04:38
  • So how can I handle it? – Mosi Apr 18 '17 at 04:47
  • @Ari0nhh What is the easiest way to handle these exceptions in mingw compiler? – Mosi Apr 18 '17 at 04:56
  • 1
    MSVC has a special language extension `__try __except` to handle SEH. On the MINGV you could use `__try1` and `__except1` macro. Also check `LibSEH` lib. – Ari0nhh Apr 18 '17 at 05:14
  • 1
    The documentation says that this function should just return -1 if no card is found, are you sure you aren't mixing it up with some other error? What message do you get exactly in the debugger when it fails? – Matteo Italia Apr 18 '17 at 05:20
  • @MatteoItalia Yes I've also checked the documentation but the application crashes and gives "has stopped working" message. – Mosi Apr 18 '17 at 05:35
  • 1
    Run it under a debugger. Most probably this function returns correctly -1 (which you are ignoring), and then what crashes is a call to another function of the same library, which you shouldn't have done because this one failed. – Matteo Italia Apr 18 '17 at 05:43
  • @MatteoItalia: unfortunately I've check it and the app crashes exactly at the function call. I've also checked the Demo provided by manufacture, it also crashes at the function call in computers where the card is not installed! – Mosi Apr 18 '17 at 05:44
  • Well then the only workaround is to intercept the SEH exception and ignore it. OTOH this is quite a big bug, the manufacturer ought to fix it to have the function return -1 cleanly. Another possibility if the vendor doesn't oblige would be to apply a binary patch to fix the library, but that would require some study. – Matteo Italia Apr 18 '17 at 05:50
  • @MatteoItalia Can you please guide me how to intercept the SEH exception in Qt with mingw? Since I've failed to use __try/__except – Mosi Apr 18 '17 at 05:53
  • @MatteoItalia: I'll be very appreciate if you give me some hints about how to use SEH exception handling in Qt-mingw. – Mosi Apr 19 '17 at 13:43
  • @MatteoItalia: Actually I've couldn't find any helpful docs about using __try1 and __except1 in net. – Mosi Apr 19 '17 at 13:59

0 Answers0