Customizable (no exception) error handling strategy in C ++

What error handling schemes do people use in C ++ when it is necessary, for reasons X or Y, to avoid exceptions? I implemented my own strategy, but I want to know what other people have come up with and discuss the discussion about the advantages and disadvantages of each approach.

Now, to explain the scheme that I use for a specific project, it can be summarized as follows. Methods that usually require quitting implement an interface, for example:

bool methodName( ...parameters.... , ErrorStack& errStack)
{
   if (someError) { errStack.frames.push_back( ErrorFrame( ErrorType , ErrorSource ) );
   return false;
   }
   ... normal processing ...
   return true;
}

in short, the returned parameter indicates whether processing was normal or an error occurred. the error stack is basically an std :: vector error frame containing detailed error information:

enum ErrorCondition {
            OK,
            StackOverflowInminent,
            IndexOutOfBounds,
            OutOfMemory
        };


        struct ErrorFrame {
            ErrorCondition condition;
            std::string source;

            ErrorFrame( ErrorCondition cnd , const char* src ) : condition(cnd) , source(src) {}

            inline bool isOK() const {
                return OK == condition;
            }
        };

        struct ErrorStack {
            std::vector< ErrorFrame > frames;

            void clear() {
                frames.clear();
            }
        };

- , , java-, . , ( - ErrorCondition), ErrorCondition, , - errorsConditions, .

+3

Source: https://habr.com/ru/post/1774220/


All Articles