码迷,mamicode.com
首页 > 编程语言 > 详细

C++ try catch

时间:2015-04-07 13:38:45      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

头文件:#include <stdexcept>

 1 double divideNumbers(double a,double b)
 2 {
 3     if(b==0)
 4     {
 5         throw std::exception("No zero");
 6     }
 7     return a/b;
 8 }
 9 
10 int main()
11 {
12     try
13     {
14         cout<<divideNumbers(100,5)<<std::endl;
15         cout<<divideNumbers(9,0)<<std::endl;
16     }
17     catch(const std::exception& ex)
18     {
19         cout<<ex.what()<<endl;
20     }
21

 

C++ try catch

标签:

原文地址:http://www.cnblogs.com/sunqin/p/4397811.html

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