异常: 传递流程

基于上述注释观察并理解异常传递流程:

  1. <?php
  2. function g1()
  3. {
  4. throw new \Exception();
  5. yield;
  6. }
  7. // a2 -> b2 ->
  8. (new AsyncTask(g1()))->begin();
  9. function g2()
  10. {
  11. yield;
  12. throw new \Exception();
  13. }
  14. // a2 (-> a4 -> a2) -> b2 -> b2 ->
  15. (new AsyncTask(g2()))->begin();
  16. function g3()
  17. {
  18. yield;
  19. throw new \Exception();
  20. }
  21. // a2 (-> a4 -> a2) -> b2 -> b2 ->
  22. (new AsyncTask(g3()))->begin();
  23. function g4()
  24. {
  25. yield;
  26. yield;
  27. throw new \Exception();
  28. }
  29. // a2 (-> a4 -> a2) (-> a4 -> a2) -> b2 -> b2 -> b2 ->
  30. (new AsyncTask(g4()))->begin();
  31. function g5()
  32. {
  33. throw new \Exception();
  34. /** @noinspection PhpUnreachableStatementInspection */
  35. yield;
  36. }
  37. function g7()
  38. {
  39. yield g5();
  40. }
  41. // (a2 -> a3) -> a2 (-> b2 -> b1 -> c) -> b2 ->
  42. (new AsyncTask(g7()))->begin();
  43. function g6()
  44. {
  45. yield;
  46. throw new \Exception();
  47. }
  48. function g8()
  49. {
  50. yield g6();
  51. }
  52. // (a2 -> a3) -> a2 -> a4 -> a2 -> b2 -> b2 -> b1 -> c -> b2 ->
  53. (new AsyncTask(g8()))->begin();
  54. function g9()
  55. {
  56. try {
  57. yield g5();
  58. } catch (\Exception $ex) {
  59. }
  60. }
  61. // a2 -> a3 -> a2 -> b2 -> b1 -> c ->
  62. (new AsyncTask(g9()))->begin();