home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBSSRC.ZIP / CATCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-20  |  374 b   |  19 lines

  1. #include <setjmp.h>
  2.  
  3. static    int    _catchval;        /* catch/throw return value */
  4.  
  5. int catch(id, fn)            /* execute fn() within a catch frame */
  6. register jmp_buf *id;
  7. register int (*fn)();
  8. {
  9.     return(setjmp(id) ? _catchval : ((*fn)()));
  10. }
  11.  
  12. throw(id, rv)                /* return rv to the id catch */
  13. register jmp_buf *id;
  14. register int rv;
  15. {
  16.     _catchval = rv;
  17.     longjmp(id, 1);
  18. }
  19.