18.8
对于一个函数来说,noexcept说明要么出现在该函数的所有声明语句和定义语句中,要么一次都不出现,编译器不能也不必在编译时验证异常说明,当函数指针拥有异常说明并表示该函数指针不会抛出异常说明时,函数指针只能指向不会抛出异常的函数,如果函数指针不表示不会抛出异常,则可以指向任何函数,即使是带有异常说明的函数
18.9
class out_of_stock : public std::runtime_error {
public:
explicit out_of_stock(const std:: string&s ): std::runtime_error(s){}
};
class isbn_mismatch: public std::logic_error {
public:
explicit isbn_mismatch(const std::string&s) : std::logic_error(s) {}
isbn_mismatch(const std::string&s, const std::string& lhs, const std::string& rhs): std::logic_error(s),left(lhs),right(rhs){}
const string left,right;
};
Sales_data&
Sales_data::operator+=(const Sales_data& sd){
if(this->bookNo != sd.bookNo){
throw isbn_mismatch("the isbns has wrong",isBn(),sd.isBn());
}
units_sold += sd.units_sold;
revenue += sd.revenue;
return *this;
}
18.10
当一个异常未被捕获时,程序将会中断,这对一些不允许中断服务的程序将是致命的
18.11
当what抛出异常时,需要在外层再try,catch一层来处理异常,一直循环
18.12
给类外层扩一份命名空间即可,在前置声明的时候必须要详细描述命名空间
18.13
当命名空间内有变量名与全局空间的一个变量名相同时,应该使用未命名的命名空间
在有易冲突的变量名时也该如此
18.14
matchLib::MatrixLib::matrix matchLib::MatrixLib::matrix::operator*(const matchLib::MatrixLib::matrix& l, const matchLib::MatrixLib::matrix& r) {};