My question simply is:
Is it possible to catch and process console/terminal closing event platform independently?
My question isn't the same as this question, or this, or this. None of the answers on these questions provide a platform independent way. So, is there any way? If yes, then what is it? Or is it flat impossible? If so, why is that? I mean, why is it not possible to develop a library that could handle this?
EDIT: As @Yakk asked, I need it to work on both Windows and Linux, with the least code repetition possible. If it helps, I'm learning basic networking. I've built a simple chat app, in which I need to add entries in a chat history file while closing the app. I've implemented a way to close it from inside the app. But, as users are more likely to click the close button, I need to be able that event to do the operations.