r/cpp • u/pavel_v • Apr 02 '26
What happens when a destructor throws
https://www.sandordargo.com/blog/2026/04/01/when-a-destructor-throws
102
Upvotes
r/cpp • u/pavel_v • Apr 02 '26
View all comments
Show parent comment
1
u/CornedBee Apr 02 '26
Our service needs to load an absurd amount of data into memory to be able to function. Idle memory footprint is around 3-8GB. Startup, loading all that data into memory and preprocessing it, takes somewhere between 5 and 15 minutes. The data changes frequently (our services processes incremental updates while it is running) so caching it for faster startup is not an option.
Individual request handling is quite isolated from each other, so a logical assertion doesn't mean corrupted global data, just most likely that some request input was broken in a way that we didn't anticipate.
Aborting the entire process for such a request would be very inefficient. Even if we were willing to keep multiple idle instances around for hot swap, the nature of the request patterns is such that startup wouldn't be able to keep up with instances going down as very similar, broken requests are sent.
So yeah, catch the exception, reply with a HTTP 500 equivalent, and move on. If you terminate, that's a serious bug.