码迷,mamicode.com
首页 > 其他好文 > 详细

yichang异常处理

时间:2018-03-14 15:00:14      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:not   log   cat   turn   name   har   mes   cout   end   

#include <iostream>
#include <cmath>
using namespace std;
double jie(double a, double b, double c);
int main()
{
cout << "begining" << endl;
double a, b, c, aa;
cout << "Pleasse input a, b, c:";
cin >> a >> b >> c;
try
{
aa = sqrt(jie(a, b, c));
cout << "x1=" << (-b + aa) / (2 * a) << endl;
cout << "x2=" << (-b - aa) / (2 * a) << endl;

}
catch (double)
{
cout << "a=" << a << endl << "this is not fit for a" << endl;

}
catch (const char *s)
{
cout << s << endl << "this is not fit for a,b,c" << endl;
}
catch (...)
{
cout << "all error is not good" << endl;
}
return 0;

}
double jie(double a, double b,double c)
{
double disc;
if (a == 0) throw 0;
else if ((disc = b * b - 4 * a * c) < 0) throw "b * b - 4 * a *c < 0";
else return disc;

}

yichang异常处理

标签:not   log   cat   turn   name   har   mes   cout   end   

原文地址:https://www.cnblogs.com/zhuzhenwei918/p/8566856.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!