首页 > 学院 > 开发设计 > 正文

exception简单实例

2019-11-07 22:55:47
字体:
来源:转载
供稿:网友
#include <iostream>#include <stdexcept>using namespace std;double divideNumbers(double inNumberator, double inDenominator) {    if (inDenominator == 0)        throw std::exception();    return (inNumberator / inDenominator);}int main(int argc, char *argv[]){    try {        std::cout << divideNumbers(2.5, 0.5) << std::endl;        std::cout << divideNumbers(2.3, 0) << std::endl;    } catch (std::exception excepiton) {        std::cout << "An exception was caught!" << std::endl;    }    return 0;}

output:

5

An exception was caught!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表