fork download
  1. # include <stdio.h>
  2.  
  3. typedef char * CharPtr ;
  4.  
  5. void Test1() throw ( CharPtr ) ;
  6. void Test2() throw ( CharPtr ) ;
  7. void Test3() throw ( CharPtr ) ;
  8.  
  9. int gNum = 0;
  10.  
  11. void Debug( bool isPrint, CharPtr variableName, int variable )
  12. {
  13. if ( !isPrint )
  14. return ;
  15.  
  16. printf( "%s is %d\n", variableName, variable );
  17. } // Debug()
  18.  
  19. void Test3() throw ( CharPtr )
  20. {
  21. try
  22. {
  23. gNum = 5;
  24. Test1();
  25. } // try
  26. catch ( CharPtr msg )
  27. {
  28. printf( "%s", msg );
  29. throw CharPtr( "Enter Test3()...\n" );
  30. } // catch
  31.  
  32. } // Test3()
  33.  
  34. void Test2() throw ( CharPtr )
  35. {
  36. try
  37. {
  38. Test3();
  39. } // try
  40. catch ( CharPtr msg )
  41. {
  42. printf( "%s", msg );
  43. throw CharPtr( "Enter Test2()...\n" );
  44. } // catch
  45.  
  46. } // Test2()
  47.  
  48. void Test1() throw ( CharPtr )
  49. {
  50. try
  51. {
  52. int a = 0;
  53. if ( gNum == 5 ) // something error
  54. {
  55. Debug( true, "a", a );
  56. throw CharPtr( "Error\n" );
  57. } // if
  58.  
  59. Test2();
  60. } // try
  61. catch ( CharPtr msg )
  62. {
  63. printf( "%s", msg );
  64. throw CharPtr( "Enter Test1()...\n" );
  65. } // catch
  66.  
  67. } // Test1()
  68.  
  69. int main()
  70. {
  71. try
  72. {
  73. Test1();
  74. } // try
  75. catch( CharPtr msg )
  76. {
  77. printf( "%s", msg );
  78. } // catch
  79.  
  80. } // main()
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
a is 0
Error
Enter Test1()...
Enter Test3()...
Enter Test2()...
Enter Test1()...