[英]Handle errors C++
So, I have a simple library-class and this class has some methods that return some values like code errors. 因此,我有一个简单的库类,该类具有一些返回一些值(如代码错误)的方法。
User_program User_program
MyClass go(arg1, arg2)
if(go.execute() == 0)
std::cout << go.result();
And my class has something like this 我班上有这样的事情
My class 我的课
int execute()
{
if((temp = doBar()) != 0)
{
return temp;
}
return SUCCESS;
}
int doBar()
{
if(foo == 1)
return DIVIDION_BY_ZERO;
if(fzz == 0)
return OPERATION_ERROR;
}
And so on. 等等。 So, is there any method to make errors more helpful, I've heard about enum with const for errors, but I don't understand how to implement it.
因此,有没有什么方法可以使错误更有用,我听说过用const枚举错误的枚举,但是我不知道如何实现。
Thanks. 谢谢。
Not sure that I understood the question right, but here is few moments. 不确定我是否理解正确的问题,但这是片刻。
2) If intresting how implemented some error check there is no need to go far. 2)如果了解如何执行某些错误检查,则无需走太远。
And also using exceptions(and dark side of C++ like RTTI) in libs is bad idea. 而且在libs中使用异常(以及RTTI等C ++的黑暗面)也是个坏主意。 But take this link too [3]
但也请使用此链接[3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.