C++ Exceptions; just say no

In case you still like to use exceptions, here is the latest C++ official paper on the cost of exceptions in C++.

P2544R0
C++ exceptions are becoming more and more problematic
Published Proposal, 2022-02-12
Author: Thomas Neumann (TUM)

That is about technical issues. But besides those there are logical issues; exceptions might be very foreign to you and me 1.

Example. The file can not be opened in your C++ code. Perhaps you might throw the exception, catch it all the way up, and exit from main(), with a message box. Something like this perhaps.

visual studio - try{ // some code }catch(Exception ex){ MessageBox.Show(ex. Message); } even in Visual Studio - devRant

A meaningless message box after an exception is caught in the Visual Studio.

But wait, this is a big app, you can not just exit from main().  Ok then perhaps try/throw/catch() “all-around a place” and thus your response will be more localized, aka “closer to the offending code? But how much more localized is good enough2? Catch around every fopen() ? Unfortunately, that leads to a heavy and slow app (again see P2544R0).

Perhaps the above is a caricature but that is approximately the logic of the exceptions “supported” code. Don’t worry unless you have to worry.


[1]. A good discussion is here. On exceptions and more.

[2]. You need to know more about the exception type being caught. Which requires an application-specific exceptions hierarchy.