home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !gcc / examples / cc / exception next >
Encoding:
Text File  |  2003-12-20  |  427 b   |  28 lines

  1. /* Simple demonstration of exception handling.  */
  2.  
  3. #include <stdio.h>
  4.  
  5. void foo (void)
  6. {
  7.   printf ("in foo\n");
  8.   throw ("hello world");
  9.   printf ("in foo shouldn't be here\n");
  10. }
  11.  
  12. int main (void)
  13. {
  14.   try {
  15.     printf ("trying foo\n");
  16.     foo ();
  17.     printf ("in main shouldn't be here\n");
  18.   }
  19.  
  20.   catch (const char *str)
  21.     {
  22.       printf ("caught exception: %s\n", str);
  23.     }
  24.  
  25.   printf ("main. exiting\n");
  26.   return 0;
  27. }
  28.