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
6
The most important part of Structured Exception Handling is that last part – handling it or, in other words, doing something useful with it!
I would guess what’s happened here is that a bunch of “Happy-Path” code – without Exception Handling – has been written and now you have to keep it alive because, sometimes, it throws Exceptions and thereby shoots itself in the foot.
I do not envy you being in this position.
Look at the code and the sorts of Exceptions being thrown and then decide at what point you can do something useful with those Exceptions.
- Smothering / swallowing . discarding them is not an option. Ever.
- Logging them to a file and losing them might work but at what cost to the Application? (And it could be hugely complex in a multi-threaded application).
- If you really can’t do anything useful with them, then perhaps the best thing to do is to let the application crash and burn …
8