小编smi*_*997的帖子

异常类 - what()函数

我目前正在处理我自己的继承的异常类,std::exception我不确定我是应该创建自己的,what()还是只调用 std::exception("message")我的类构造函数.这是我目前的代码:

FilterException::FilterException(const char* message, int num) noexcept :
    error_message(message), error_number(num) {}

const char* FilterException::what() const noexcept
{
    return error_message.c_str();
}

FilterException::~FilterException() noexcept
{
}

int FilterException::getErrorNumber() const noexcept
{
    return error_number;
}
Run Code Online (Sandbox Code Playgroud)

所以,我的问题,我应该像这样离开它,还是在构造函数中做出改变并摆脱what()

c++ error-handling exception

4
推荐指数
1
解决办法
188
查看次数

float的printf()为十六进制数

我很难理解为什么这个代码会导致3f000000.

float f = 5e-1;
printf("%x", *(int*)&f);
Run Code Online (Sandbox Code Playgroud)

c

-1
推荐指数
2
解决办法
827
查看次数

标签 统计

c ×1

c++ ×1

error-handling ×1

exception ×1