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 me and you1.

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: " Exception!" + x.what()? 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 the heavy and slow app (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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: