当前位置: 首页 > news >正文

网站服务器类型查询六枝特区建设局网站

网站服务器类型查询,六枝特区建设局网站,微信上怎么做网站,酒店网站设计模板一、异常处理手段 抛出异常#xff1a;throw 异常 作用#xff1a;让调用者看见这个异常#xff0c;如果调用者不理睬#xff0c;就让调用者的调用者看见 接住异常: try {可能异常的code} catch(异常类型) {处理方式} 异常类型#xff1a;一般为const #xff0c;防…一、异常处理手段 抛出异常throw 异常 作用让调用者看见这个异常如果调用者不理睬就让调用者的调用者看见 接住异常: try {可能异常的code} catch(异常类型) {处理方式} 异常类型一般为const 防止copy; 如果 不确定异常类型也可以用catch(...){处理方式}并且在catch中仍可用throw继续抛 二、标准异常类 都继承于 exception 这个基类异常的类型 bad_alloclogic_error  length_errorout_of_range (stl容器调用at)domain_errorinvalid_argumentruntime_error range_erroroverflow_errorunderflow_errorbad_castcatch(...)一般写在异常类型的最后 例子 #include iostream #include vectorvoid strcpy(char *dest, const char *source) {if (!dest || !source)throw std::invalid_argument(Null Pointers pass to strcpy.);while (*source)*dest *source;*dest \0; }template typename T class Array { public:Array(std::size_t n)try : m_size(n), m_data(new T[n]){}catch (const std::bad_alloc ba){std::cout No enough memory. std::endl;throw;}private:size_t m_size;int *m_data; };int main() {char *dest nullptr;const char *source hello;try{strcpy(dest, source);}catch (const std::invalid_argument e){std::cout invalid_argument std::endl;std::cout e.what() std::endl;}catch (...){std::cout catch std::endl;}return 0; } 三、栈展开 栈展开作用: 销毁局部变量 四、构造函数try-catch template typename T class Array { public:Array(std::size_t n)try : m_size(n), m_data(new T[n]) //写法比较特殊{}catch (const std::bad_alloc ba){std::cout No enough memory. std::endl;throw;}private:size_t m_size;int *m_data; }; 五、异常安全保证 不抛异常(Nothrow guarantee)保证不抛出异常强异常安全保证(Strong guarantee)抛出异常程序状态不变弱异常安全保证(Weak guarantee)状态改变但在有效状态 六、不抛出异常 noexcept 关键字可以让编译器进行更好的优化 如果函数声明了noexcept, 但还是抛出了一场调用栈可能开解(直接崩溃) note移动构造 和 移动赋值 不声明为noexcept比那一期是不敢用的noexcept的两种特殊用法 noexcept(bool) : 相当于开关noexcept的作用noexcept(true)  noexcept(bool);noexcept(noexcept(std::swap(thing,other.thing))) : 这个noexcept是一个表达式。根据内部函数是够抛异常决定返回true/false 七、copyswap #include vector #include string #include iostream// class Buffer // { // private: // unsigned char *_buf; // int _capacity; // int _length;// public: // explicit Buffer(int capacity) : _capacity(capacity), _length(0) // { // std::cout Buffer(int capacity) std::endl; // // throw std::invalid_argument(); // _buf capacity 0 ? nullptr : new unsigned char[capacity]{}; // }// ~Buffer() // { // std::cout ~Buffer() std::endl; // delete[] _buf; // }// Buffer(const Buffer buffer) // { // std::cout Buffer(const Buffer buffer) std::endl; // this-_capacity buffer._capacity; // this-_length buffer._length; // // throw std::invalid_argument(); // this-_buf new unsigned char[buffer._capacity]; // std::copy(buffer._buf, buffer._buf buffer._capacity, this-_buf); // }// Buffer(Buffer buffer) noexcept // { // std::cout Buffer(Buffer buffer) std::endl; // this-_capacity buffer._capacity; // this-_length buffer._length; // this-_buf buffer._buf;// buffer._buf nullptr; // buffer._capacity 0; // buffer._length 0; // }// Buffer operator(const Buffer buffer) // { // std::cout Buffer operator(const Buffer buffer) std::endl; // if (this ! buffer) // { // this-_capacity buffer._capacity; // this-_length buffer._length; // delete[] this-_buf; // throw std::invalid_argument(....); // this-_buf new unsigned char[buffer._capacity]; // std::copy(buffer._buf, buffer._buf buffer._capacity, this-_buf); // } // return *this; // }// Buffer operator(Buffer buffer) noexcept // { // std::cout Buffer operator(Buffer buffer) std::endl; // if (this ! buffer) // { // this-_capacity buffer._capacity; // this-_length buffer._length; // delete[] this-_buf; // this-_buf buffer._buf;// buffer._buf nullptr; // buffer._capacity 0; // buffer._length 0; // } // return *this; // }// bool write(unsigned char value) noexcept // { // if (_length _capacity) // return false; // _buf[_length] value; // return true; // } // };class Buffer { private:unsigned char *_buf;int _capacity;int _length;public:explicit Buffer(int capacity) : _capacity(capacity), _length(0){_buf capacity 0 ? nullptr : new unsigned char[capacity];}~Buffer(){delete[] _buf;}friend void swap(Buffer lhs, Buffer rhs);Buffer(const Buffer buffer) : _capacity(buffer._capacity),_length(buffer._length),_buf(_capacity 0 ? nullptr : new unsigned char[_capacity]){std::copy(buffer._buf, buffer._buf buffer._capacity, this-_buf);}Buffer(Buffer buffer) noexcept : Buffer(0){swap(buffer, *this);}Buffer operator(Buffer buffer) // 会做一次拷贝构造/移动构造根据传入参数类型确定{swap(buffer, *this);return *this;}bool write(unsigned char value) noexcept{if (_length _capacity)return false;_buf[_length] value;return true;} };void swap(Buffer lhs, Buffer rhs) {using std::swap;swap(lhs._buf, rhs._buf);swap(lhs._capacity, rhs._capacity);swap(lhs._length, rhs._length); }class BitMap { public:explicit BitMap(size_t size) : _buffer(size) {}static void Swap(BitMap lhs, BitMap rhs){using std::swap;swap(lhs._buffer, rhs._buffer);}private:Buffer _buffer; };int main() {int *a nullptr;Buffer buffer(10);buffer.write(52);buffer.write(37);Buffer buffer1(20);buffer1.write(20);buffer1.write(111);swap(buffer, buffer1);// try// {// buffer1 buffer;// }// catch (...)// {// std::cout error std::endl;// }// buffer.write(52);// buffer.write(37);// Buffer buffer1(20);// buffer1.write(20);// buffer1.write(111);// try// {// buffer1 buffer;// }// catch (...)// {// std::cout error std::endl;// }// std::cout over std::endl; }// Buffer buffer Buffer(10); // buffer Buffer(16);
http://www.hkea.cn/news/14528895/

相关文章:

  • 建设部信息中心网站东莞网络科技营销
  • 两学一做专题网站素材英文网站建设哪家好
  • 青岛网站制作seo《网站建设教程
  • 贸易网站怎么做如何向百度提交网站
  • 保洁公司 网站模板本地唐山网站建设
  • 做网站兼职wordpress验证登录页面
  • design设计网站html5视频标签
  • 樟木头网站仿做优化大师人工服务电话
  • 微官网与网站的区别流行的网站设计风格
  • 带数据库的网站模板域名ip查询查网址
  • 电商网站建设与管理文联网站建设方案
  • 做网站选哪家公司网站欣赏网站
  • 网站正在建设中页面的英文wordpress无法选择数据库
  • 网站编辑容易做吗cumfoot wordpress
  • 用dw做网站时怎么添加弹窗开发公司退房款代理词
  • 快手做任务网站7有免费建网站
  • wordpress统一网站图片大小wordpress 代码执行
  • 网站建设 国家技术规范网页怎么做才美观
  • 东莞纸箱厂东莞网站建设江苏网站建设seo优化
  • 做一个购物网站多少钱广州互联网
  • 人才网站 建设好 窗口wordpress 繁简转换插件
  • 做效果图常用的网站9420高清免费视频在线观看
  • 怎么自己做彩票网站网站顶部地图代码怎么做
  • 那个网站系统好山东东成建设咨询有限公司网站
  • 营销型网站建设排名营销策划的流程
  • 镇江高端网站建设工作室网站什么时候做SEO优化最合适
  • 苏州网络营销网站建设平台网站域名可以做端口映射吗
  • 凯里网络公司建设网站买网站做淘宝客
  • 网站建设都分几个阶段那种网站打不开
  • 企业类网站源码西安公积金 网站建设