Skip to main content
2 of 2
added 221 characters in body
Mawg
  • 4.3k
  • 4
  • 37
  • 51

How to catch every exception in a multi-threaded C++ app with the minumum of code?

I have been tasked with the title above. There is currently zero exception handling. There are 100+ threads, all created from main().

Exceptions won't percolate up to main() - they won't leave the thread.

Each thread has a Make() function, invoked from main(), which initializes the data and subscribes to async messages. The system framework delivers the messages by invoking callbacks which were passed in the subscribe() function.

I don't think that I can wrap each thread in its own try catch. I fear that I must have a try/catch in each message handler, and management would baulk at that, as each thread has a dozen or so subscribed messages, meaning adding 1,000+ try/catch.

Is there a simpler solution, using C++ 14? Host is Windows and target is VxWorks, if that makes any difference.


Bottom line, I would have to add try/catch to every callback which handles a message, over 500 of them. I suggested a Python script, but it was decided to forget exceptions and go with a heartbeat mechanism

Mawg
  • 4.3k
  • 4
  • 37
  • 51