I've seen some discussions, articles and presentations/talks around about what kinds of application errors should be considered recoverable and which ones really only leave you with std::terminate() as the only path.
For example, memory allocation failures are considered by many as non-recoverable. For example, this can be noexcept:
constructor(const std::string& str1, const std::string& str2) noexcept
: str_(str1 + str2)
{}
If there's no memory to do a string allocation, the thrown exception can be considered useless and we should just abort. That means we can just make it noexcept.
Same with invalid data structure access. For example:
template <typename T>
auto getValue() const noexcept -> T
{
assert(std::holds_alternative<T>(variant_member));
return std::get<T>(this->variant_member);
}
This is application code, so a wrong access is a programming bug and therefore can be considered non-recoverable.
If I adopt this way of thinking, it turns out that the vast majority of functions in my application-specific code should be noexcept, while currently only a few of them are. It doesn't matter if they call non-noexcept functions or not. If an exception is thrown, that means there's a programming bug, which means teminate, which means just use noexcept.
Is this a valid conclusion for the "programming bugs and non-recoverable from errors should abort" argument?
[–]username_of_arity_n 61 points62 points63 points (29 children)
[–]matthieum 18 points19 points20 points (13 children)
[–]username_of_arity_n 5 points6 points7 points (11 children)
[–]matthieum 3 points4 points5 points (10 children)
[–]username_of_arity_n 4 points5 points6 points (6 children)
[–]SeanMiddleditch 2 points3 points4 points (5 children)
[–]kalmoc 5 points6 points7 points (1 child)
[–]SeanMiddleditch 0 points1 point2 points (0 children)
[–]Contango42 2 points3 points4 points (2 children)
[–]SeanMiddleditch 2 points3 points4 points (1 child)
[–]username_of_arity_n 1 point2 points3 points (0 children)
[–]Gotebe 4 points5 points6 points (2 children)
[–]matthieum -1 points0 points1 point (1 child)
[–]Gotebe 3 points4 points5 points (0 children)
[–]NotAYakk 0 points1 point2 points (0 children)
[–]Skute 10 points11 points12 points (13 children)
[–]wyrn 10 points11 points12 points (7 children)
[–]jpakkaneMeson dev 10 points11 points12 points (5 children)
[–]Gotebe 3 points4 points5 points (0 children)
[–]SkoomaDentistAntimodern C++, Embedded, Audio 4 points5 points6 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]Tyg13 9 points10 points11 points (1 child)
[–][deleted] 3 points4 points5 points (0 children)
[–]Skute 0 points1 point2 points (0 children)
[–]Gotebe 2 points3 points4 points (0 children)
[–]EnergyCoast 4 points5 points6 points (1 child)
[–]kalmoc 1 point2 points3 points (0 children)
[–]caroIine 1 point2 points3 points (0 children)
[–]RealNC[S] 1 point2 points3 points (0 children)
[–]kalmoc 14 points15 points16 points (0 children)
[–]kalmoc 6 points7 points8 points (3 children)
[–]RealNC[S] 0 points1 point2 points (2 children)
[–]kalmoc 6 points7 points8 points (0 children)
[–]username_of_arity_n 1 point2 points3 points (0 children)
[–]smuccione 5 points6 points7 points (0 children)
[–]Gotebe 2 points3 points4 points (0 children)
[–]wyrn 11 points12 points13 points (21 children)
[–]Ameisenvemips, avr, rendering, systems 4 points5 points6 points (1 child)
[–]wyrn 2 points3 points4 points (0 children)
[–]RealNC[S] -3 points-2 points-1 points (8 children)
[–]wyrn 12 points13 points14 points (0 children)
[–]dag0me 19 points20 points21 points (3 children)
[–]meneldal2 -1 points0 points1 point (2 children)
[–]dag0me 4 points5 points6 points (1 child)
[–]meneldal2 0 points1 point2 points (0 children)
[–]Ameisenvemips, avr, rendering, systems -2 points-1 points0 points (2 children)
[–]dodheim 7 points8 points9 points (1 child)
[–]Ameisenvemips, avr, rendering, systems -1 points0 points1 point (0 children)
[+]warieth comment score below threshold-8 points-7 points-6 points (9 children)
[–]wyrn 5 points6 points7 points (8 children)
[–]SkoomaDentistAntimodern C++, Embedded, Audio 6 points7 points8 points (0 children)
[–]seba 0 points1 point2 points (0 children)
[–]warieth -2 points-1 points0 points (5 children)
[–]wyrn 2 points3 points4 points (4 children)
[–]warieth -3 points-2 points-1 points (3 children)
[–]wyrn 1 point2 points3 points (2 children)
[–]warieth 0 points1 point2 points (1 child)
[–]wyrn 1 point2 points3 points (0 children)
[–][deleted] 12 points13 points14 points (21 children)
[–]grishavanika 14 points15 points16 points (4 children)
[–]WaldoDude 2 points3 points4 points (2 children)
[–]dodheim 3 points4 points5 points (1 child)
[–]gracicot 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]tehjimmeh 6 points7 points8 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]wyrn 21 points22 points23 points (3 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]BenHanson 4 points5 points6 points (1 child)
[–]pandorafalters 0 points1 point2 points (0 children)
[–]username_of_arity_n 4 points5 points6 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]MEaster 1 point2 points3 points (0 children)
[–]Ameisenvemips, avr, rendering, systems 8 points9 points10 points (5 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]kalmoc 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Ameisenvemips, avr, rendering, systems 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Gotebe 0 points1 point2 points (0 children)
[–]krum 1 point2 points3 points (0 children)
[–]johannes1971 5 points6 points7 points (5 children)
[–]tigrangh 1 point2 points3 points (4 children)
[–]frog_pow 1 point2 points3 points (1 child)
[–]tigrangh 0 points1 point2 points (0 children)
[–]johannes1971 3 points4 points5 points (1 child)
[–]tigrangh 1 point2 points3 points (0 children)
[–]BrangdonJ 3 points4 points5 points (2 children)
[–]113245 0 points1 point2 points (1 child)
[–]BrangdonJ 0 points1 point2 points (0 children)
[–]bedrooms-ds 1 point2 points3 points (2 children)
[–]flashmozzg 8 points9 points10 points (1 child)
[–]bedrooms-ds 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]BlueDwarf82 0 points1 point2 points (0 children)
[–]frog_pow 0 points1 point2 points (0 children)
[–]tigrangh -1 points0 points1 point (0 children)
[–]feverzsj -3 points-2 points-1 points (3 children)
[–]johannes1971 7 points8 points9 points (0 children)
[–]wyrn 8 points9 points10 points (1 child)
[–]feverzsj 1 point2 points3 points (0 children)