zoukankan      html  css  js  c++  java
  • 137.CPP自带异常

     1 #include <iostream>
     2 #include <exception>
     3 using namespace std;
     4 
     5 //继承自带的异常
     6 class sizeerror :public exception
     7 {
     8 public:
     9     sizeerror() :exception("尺寸大小异常")
    10     {
    11 
    12     }
    13 
    14     const char *what()
    15     {
    16         char *p = "尺寸大小异常";
    17         cout << "尺寸大小异常" << endl;
    18         return p;
    19     }
    20 };
    21 
    22 class print3d
    23 {
    24 public:
    25     print3d(double size)
    26     {
    27         if (size > 100)
    28         {
    29             throw &sizeerror();
    30         }
    31     }
    32 };
    33 void main()
    34 {
    35     try
    36     {
    37         print3d p(300);
    38     }
    39     catch (sizeerror *p)
    40     {
    41         p->what();
    42     }
    43     cin.get();
    44 }
  • 相关阅读:
    观察者模式
    工厂模式
    单例模式
    代理模式
    策略模式
    Ioc容器
    Spring概述
    02:入门
    01:背景
    编译原理感悟
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8688030.html
Copyright © 2011-2022 走看看