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

兰州大学网页与网站设计yy直播是免费的吗

兰州大学网页与网站设计,yy直播是免费的吗,WordPress三大标签插件,咸阳seo公司1.什么是异常,什么是错误? 程序无法保证100%正确运行,万无一失。有的错误在编译时能发现,比如:关键字拼写、变量名未定义、括号不配对、语句末尾缺分号等。这是在编译阶段发现的,称为编译错误。 有的能正常…

1.什么是异常,什么是错误?

程序无法保证100%正确运行,万无一失。有的错误在编译时能发现,比如:关键字拼写、变量名未定义、括号不配对、语句末尾缺分号等。这是在编译阶段发现的,称为编译错误。
有的能正常通过编译,也能运行,但在运行过程中出现异常。出现异常,系统不应该崩溃退出,而应该给用户提示,让他改对输入。
比如:计算过程,出现除数为0, 内存空间不够、无法打开输入文件。 这体现了系统的容错能力。
**异常处理:**对运行时出现的差错以及其它例外情况的处理。

2.如何处理异常

#include<iostream>
#include<cmath>
using namespace std;
int main(){double triangle(double,double,double);cout << "pls input three double num and make a triangle:" << endl;double a,b,c, area;cin >> a >> b >> c;try{while(a>0&&b>0&&c>0){area = triangle(a,b,c);}}catch(double){cout << "error!" << endl;}catch(const std::exception& e){std::cerr << e.what() << '\n';}cout << "the result:" << area << endl;return 0;}double triangle(double a,double b,double c){double area;double s = (a+b+c)/2;if(a+b<=c||a+c<=b||b+c<=a){throw a;}area = sqrt(s*(s-a)*(s-b)*(s-c));return area;
}

可以捕获任何类型的错误,用来兜底使用

catch(....){cout << "ERROR! << endl;
}

上层调用侧将异常信息原样抛出

catch(int){throw;// 将已捕获的异常信息再次原样输出
}

3.在函数声明中进行异常情况指定

php7 开始有了这种情况,原来是从C++来的

double triangle(double,double,double) throw(double);

表示函数只能抛出double类的异常。

double triangle(double,double,double) throw(double,int, float, char);

表示函数只能抛出double,int, float, char类的异常。

表示一个不能抛出异常的函数,程序将非正常终止

double triangle(double,double,double) throw();

4. 进阶

4.1 在异常处理中处理析构函数?

我记得php中也对此有过讨论。好像还能手动修改。
先执行 destruct 在执行 catch

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
class Student{
public:Student(int n, string nam){num = n;name = nam;cout << "constructor-" << num << endl;}~Student(){cout << "destructor-" << num << endl;}void get_data();
private:int num;string name;};void Student::get_data(){if (num==0){throw num;}else{cout << num << " " << name << endl;cout << "in get_data() " << endl;}
}void fun(){Student stud1(1101,"Tan");stud1.get_data();Student stud2(0,"li");stud2.get_data();
}int main(){cout << "main begin" << endl;cout << "call fun()" << endl;try{fun();}catch(int n){cout << "num="<<n<<",error!"<<endl;}cout << "main end" << endl;return 0;}

输出内容:

main begin
call fun()
constructor-1101
1101 Tan
in get_data()
constructor-0destructor-0destructor-1101
num=0,error!
main end

4.2 如何在catch中获取堆栈信息?

http://www.yayakq.cn/news/609884/

相关文章:

  • 建设企业学习网站内蒙住房和城乡建设部网站
  • 上海十大保安公司排名湖南优化网站建设
  • 网站建设公司 信科网络菜单设计制作图片
  • 上海网站建设上海网站制作wordpress要多少钱
  • 做营销网站推广网页制作工具按其制作方式
  • 西安便宜的网站建设怎么用7牛云做网站
  • 甘肃省建设工程造价信息网站wordpress自动播放音乐
  • 美的企业微信网站怎样维护网站
  • 实用网站模板企业管理系统源码
  • 宁波 做网站的条幅在线设计网站
  • 为网站做seo网站死链怎么办
  • 公司招聘网站有哪些南阳商城站
  • 站长工具seo学生个人网站模板
  • 怎么做网站关键词优化高密市建设局网站
  • 商务网站建设简答题及答案小程序软件开发哪家好
  • seo网站诊断流程上海自助建站
  • 京东网站设计特点网站备案基础知识
  • 南平住房和城乡建设部网站做英文网站需要多长时间
  • 帝国做的电影网站揭阳设计公司
  • 重庆企业做网站浏阳做网站公司
  • 建站工具 ip做个手机网站
  • 怎样建设网站呢做网站销售的技巧
  • 常德建设网站多少钱云南网架加工
  • 瀑布流网站有哪些外贸网站如何建站
  • 坪山公司网站建设wordpress 管理员邮箱
  • 网站建设 后端前端erp系统怎么自学
  • 能自己做二次元人物的网站数据营销系统
  • 潮州网站搭建找谁sql网站模板
  • 网站制作在哪里找网络舆情管理
  • 网站开发需要技术简单的网站设计图