Exception Handling instance code in C ++ Programming

Source: Internet
Author: User

  1. # Include <iostream>
  2. # Include <csetjmp>
  3. Using namespace std;
  4. Class Rainbow {
  5. Public:
  6. Rainbow () {cout <"Rainbow ()" <endl ;}
  7. ~ Rainbow () {cout <"~ Rainbow () "<endl ;}
  8. };
  9. Void oz (){
  10. Rainbow rb;
  11. For (int I = 0; I <3; I ){
  12. Cout <"theres no place like home" <endl;
  13. }
  14. Throw 47;
  15. }
  16. Int main ()
  17. {
  18. Try {
  19. Cout <"tornado, witch, muchkins..." <endl;
  20. Oz ();
  21. }
  22. Catch (int ){
  23. Cout <"Autie Em! "
  24. <"I had the strangest dream ..."
  25. <Endl;
  26. }
  27. Return 0;
  28. }
  29. Output:
  30. Tornado, witch, muchkins...
  31. Rainbow ()
  32. Theres no place like home
  33. Theres no place like home
  34. Theres no place like home
  35. ~ Rainbow ()
  36. Autie Em! I had the strangest dream...
  37.  
  38. Process returned 0 (0x0) execution time: 0.094 s
  39. Press any key to continue.

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.