fork download
  1. #include <stdio.h>
  2. #include <setjmp.h>
  3.  
  4. struct jmp_buf_struct
  5. {
  6. jmp_buf jb;
  7. void* exc_ptr;
  8. };
  9.  
  10. void may_throw(jmp_buf jb)
  11. {
  12. struct jmp_buf_struct* jbs_ptr = (struct jmp_buf_struct*)jb;
  13. jbs_ptr->exc_ptr = "Exception message!";
  14. longjmp(jb, 1);
  15. }
  16.  
  17. int main()
  18. {
  19. struct jmp_buf_struct jbs;
  20. if (setjmp(jbs.jb))
  21. {
  22. printf("Threw %p = \"%s\".", jbs.exc_ptr, (char*)jbs.exc_ptr);
  23. }
  24. else
  25. {
  26. may_throw(jbs.jb);
  27. puts("Didn't throw.");
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Threw 0x55638ebc78c4 = "Exception message!".