Skip to content

Commit 4481351

Browse files
authored
allow using raising err inside implementation (#126)
this allows writing `raise InterpreterError` inside a method table, one can still return a `interp.Err`, but using `raise` would simplify things sometimes because Python does not have syntax sugar for error types.
1 parent f494442 commit 4481351

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/kirin/interp/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ def eval_stmt(
204204
"simply evaluate a statement"
205205
method = self.lookup_registry(frame, stmt)
206206
if method is not None:
207-
return method(self, frame, stmt)
207+
try:
208+
return method(self, frame, stmt)
209+
except InterpreterError as e:
210+
return Err(e, self.state.frames)
208211

209212
# NOTE: not using f-string here because 3.10 and 3.11 have
210213
# parser bug that doesn't allow f-string in raise statement

0 commit comments

Comments
 (0)