Skip to content

Commit 20b8f59

Browse files
committed
catching uncatched Throw
1 parent 78a75ef commit 20b8f59

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

mathics/builtin/control.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ class Throw(Builtin):
788788
= ...
789789
<< Catch[NestList[If[# > 1000, Throw[#], #^2 + 1] &, 1, 7]]
790790
= 458330
791-
791+
<< Throw[1]
792+
= Null
792793
"""
793794
messages = {'nocatch': 'Uncaught `1` returned to top level.', }
794795

mathics/core/evaluation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ def evaluate():
336336
self.exc_result = Expression("Overflow")
337337
else:
338338
raise
339+
except WLThrowInterrupt as ti:
340+
print("query: ", query)
341+
if ti.tag:
342+
self.exc_result = Expression("Hold",
343+
Expression("Throw",
344+
ti.value,
345+
ti.tag))
346+
else:
347+
self.exc_result = Expression("Hold",
348+
Expression("Throw",
349+
ti.value
350+
))
351+
self.message("Throw", "nocatch", self.exc_result)
339352
except OverflowError:
340353
self.message("General", "ovfl")
341354
self.exc_result = Expression("Overflow")

0 commit comments

Comments
 (0)