Posted to tcl by sebres at Tue Sep 17 18:55:25 GMT 2019view raw

  1. # ---------------------------------------------------
  2. # 1.a catch is main command - catch is in call stack:
  3. # ---------------------------------------------------
  4.  
  5. % catch { \
  6. \
  7. \
  8. proc foo {} { \
  9. \
  10. \
  11. error test
  12. }
  13. foo
  14. }; puts $::errorInfo
  15.  
  16. test
  17. while executing
  18. "error test"
  19. (procedure "foo" line 1)
  20. invoked from within
  21. "foo"
  22. invoked from within
  23. "catch { \
  24. \
  25. \
  26. proc foo {} { \
  27. \
  28. \
  29. error test
  30. }
  31. foo
  32. }"
  33.  
  34. # ---------------------------------------------------
  35. # 1.b now put eval around - catch is NOT in call stack:
  36. # ---------------------------------------------------
  37. % eval {catch { \
  38. \
  39. \
  40. proc foo {} { \
  41. \
  42. \
  43. error test
  44. }
  45. foo
  46. }; puts $::errorInfo}
  47.  
  48. test
  49. while executing
  50. "error test"
  51. (procedure "foo" line 1)
  52. invoked from within
  53. "foo"
  54.  
  55. # =======================================================================================
  56.  
  57. # ---------------------------------------------------
  58. # 2. info frame vs. proc - [info frame] is in line 4, [error] in line 1
  59. # ---------------------------------------------------
  60.  
  61. % eval {catch { \
  62. \
  63. \
  64. proc foo {} { \
  65. \
  66. \
  67. error [info frame 0]
  68. }
  69. foo
  70. }; puts $::errorInfo}
  71.  
  72. type proc line 4 cmd {info frame 0} proc ::foo level 0
  73. while executing
  74. "error [info frame 0]"
  75. (procedure "foo" line 1)
  76. invoked from within
  77. "foo"
  78.  
  79. # =======================================================================================
  80.  
  81. # ---------------------------------------------------
  82. # 3.1 file - error in file, line 9
  83. # ---------------------------------------------------
  84.  
  85. $ echo '\
  86. \
  87. \
  88. proc foo {} { \
  89. \
  90. \
  91. error test
  92. }
  93. foo
  94. ' > /tmp/test | ./tcltest /tmp/test
  95.  
  96. test
  97. while executing
  98. "error test"
  99. (procedure "foo" line 1)
  100. invoked from within
  101. "foo"
  102. (file "/tmp/test" line 9)
  103.  
  104. # ---------------------------------------------------
  105. # 3.2 file (with eval around) - error in file, line 1
  106. # ---------------------------------------------------
  107.  
  108. $ echo 'eval {\
  109. \
  110. \
  111. proc foo {} { \
  112. \
  113. \
  114. error test
  115. }
  116. foo
  117. }' > /tmp/test | ./tcltest /tmp/test
  118.  
  119. test
  120. while executing
  121. "error test"
  122. (procedure "foo" line 1)
  123. invoked from within
  124. "foo"
  125. ("eval" body line 3)
  126. invoked from within
  127. "eval {\
  128. \
  129. \
  130. proc foo {} { \
  131. \
  132. \
  133. error test
  134. }
  135. foo
  136. }"
  137. (file "/tmp/test" line 1)
  138.