C + + Exception hierarchy

Source: Internet
Author: User

1 #define_crt_secure_no_warnings2#include <iostream>3 4 using namespacestd;5 6 classMyArray7 {8  Public:9MyArray (intlen);Ten~MyArray (); One  A  Public: -     int&operator[](intindex); -     intGetlen (); the  -  Public: -     classesize -     { +      Public: -Esize (intlen) +         { ASize =Len; at         } -         Virtual voidPrintferr () -         { -cout <<"Size:"<< size <<Endl; -         } -     protected: in         intsize; -     Private: to     }; +  -     classEnegative: Publicesize the     { *      Public: $Enegative (intsize): esize (size)Panax Notoginseng         { -             ; the         } +         Virtual voidPrintferr () A         { thecout <<"enegative Exception Size:"<< size <<Endl; +         } -     protected: $     Private: $     }; -     classEzero: Publicesize -     { the      Public: -Ezero (intsize): esize (size)Wuyi         { the             ; -         } Wu         Virtual voidPrintferr () -         { Aboutcout <<"Ezero Exception Size:"<< size <<Endl; $         } -     protected: -     Private: -     }; A     classEtoobig: Publicesize +     { the      Public: -Etoobig (intsize): esize (size) $         { the             ; the         } the         Virtual voidPrintferr () the         { -cout <<"Etoobig Exception Size:"<< size <<Endl; in         } the     protected: the     Private: About     }; the     classEtoosmall: Publicesize the     { the      Public: +Etoosmall (intsize): esize (size) -         { the             ;Bayi         } the         Virtual voidPrintferr () the         { -cout <<"Etoosmall Exception Size:"<< size <<Endl; -         } the     protected: the     Private: the     }; the  -  the protected: the Private: the     int*M_space;94     intM_len; the }; the  the 98  AboutMyarray::myarray (intlen) - {101     if(Len <0)102     {103         Throwenegative (len);104     } the     Else if(len = =0)106     {107         ThrowEzero (len);108     }109     Else if(Len > +) the     {111         ThrowEtoobig (len); the     }113     Else if(Len <3) the     { the         ThrowEtoosmall (len); the     }117 118M_len =Len;119M_space =New int[Len]; - }121 122myarray::~MyArray ()123 {124     if(M_space! =NULL) the     {126         Delete[]m_space;127M_space =NULL; -M_len =0;129     } the     131 } the int& MyArray::operator[](intindex)133 {134     returnM_space[index];135 }136 intMyarray::getlen ()137 {138     returnM_len;139 } $ 141 intMainvoid)142 {143     Try144     {145MyArray A (1);146          for(intI=0; I<a.getlen (); i++)147         {148A[i] = i+1;149printf"%d", A[i]); Max         }151     } the     Catch(myarray::esize&e)153     {154 E.printferr ();155     }156 157     Catch (...)158     {159         ; the     }161 162 163 164cout <<"Hello world!"<<Endl;165System"Pause");166     return 0;167}

C + + Exception hierarchy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.