English 中文(简体)
c++的习俗(非例外)错误处理战略
原标题:custom (non-exception) error handling strategy in c++

如果出于X或Y原因有必要,在++中采用哪些错误处理办法避免例外情况? 我已经执行了我自己的战略,但我想知道其他人的到来,并就每个办法的效益和缺点展开讨论。

现在,为了解释在某个特定项目中采用“i m”办法,可以总结一下。 2. 通常要求投掷的方法,如:

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

简言之,回归参数是指加工是ok还是有误。 The Error Stack is basic a 档:vector of misframe which contained details information about the wrong:

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();
            }
        };

这种做法的好处是,存在类似于支离破碎例外情况的错误,但是没有例外的操作时间。 主要的缺点是,(除了非标准性之外,如果仍然必须处理第三方法的例外情况,某种方式和排在傲慢状态之外),很难坚持这种傲慢状态,因为来源基础的多个组成部分需要不同的错误,因此,这一战略的第二版可能会对错误条件使用某种继承等级,但对于实现这种制度的最佳方式仍然缺乏信心。

问题回答

http://www. open-std.org/jtc1/sc22/wg21/docs/TR18015.pdf”rel=“nofollow” http://www. open-std.org/jtc1/sc22/wg21/docs/TR18015.pdf 第32页





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签