Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // Testing Coroutine Exception Throwing
  6. // using namespace std;
  7. // _Event E {};
  8. //
  9. // _Coroutine C {
  10. // void main() { _Throw E(); }
  11. // public:
  12. // void mem() { resume(); }
  13. // };
  14. //
  15. // int main() {
  16. // C c;
  17. // try {
  18. // c.mem(); // first call fails
  19. // } catch ( ... ) {
  20. // cout << "caught!!!" << endl;
  21. // }
  22. // }
  23.  
  24. // question for peter
  25. // func {
  26. // something broke
  27. // _resume
  28. // continue running
  29. // }
  30. //
  31. // try {
  32. // func
  33. // } catchresume {
  34. // if i can fix it {
  35. // cout <<
  36. // } else {
  37. // Throw
  38. // }
  39. // } catch {
  40. //
  41. // }
  42. // this runs next
  43.  
  44. _Coroutine Test {
  45. // YOU ADD MEMBERS HERE
  46. char ch;
  47. void main() {
  48. for (;;) {
  49. cout << "hey" << endl;
  50. _Resume Error() _At resumer();
  51. cout << "hey2" << endl;
  52. suspend();
  53. }
  54. }
  55. public:
  56. _Event Match {}; // last character match // last character invalid
  57. _Event Error {};
  58. void next() {
  59. resume(); // activate
  60. }
  61. };
  62.  
  63.  
  64. int main() {
  65. Test c;
  66. try {
  67. c.next();
  68. } catch ( Test::Error e ) {
  69. cout << "hey i caught it" << endl;
  70. }
  71. // c.next();
  72.  
  73. C: {
  74. cout << "abc" << endl;
  75. break C;
  76. cout << "cba" << endl;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement