gpt4 book ai didi

c++ - 一个关于派生标准异常类的问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:01:37 27 4
gpt4 key购买 nike

/* user-defined exception class derived from a standard class for exceptions*/

class MyProblem : public std::exception {

public:

...

MyProblem(...) { //special constructor
}

virtual const char* what() const throw() {
//what() function
...
}

};

...

void f() {
...

//create an exception object and throw it

throw MyProblem(...);

...


}

我的问题是为什么what()之后有一个“const throw()”? 通常,如果有 throw() ,则表示 throw() 之前的函数 可以抛出异常,但是这里为什么会抛出异常呢?

最佳答案

"throw()" 中的空括号表示函数不抛出。

关于c++ - 一个关于派生标准异常类的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/498835/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com