Skip to content

Commit

Permalink
Refactor code for exception and raise
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed Sep 4, 2023
1 parent a9bea86 commit cd5975e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,9 @@ Value Env::exception_object() {

ExceptionObject *Env::exception() {
auto e = this;
for (;;) {
while (e) {
if (e->m_exception)
return e->m_exception;
if (!e->m_caller)
break;
e = e->m_caller;
}
return nullptr;
Expand Down
5 changes: 2 additions & 3 deletions src/kernel_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,8 @@ Value KernelModule::puts(Env *env, Args args) {

Value KernelModule::raise(Env *env, Value klass, Value message) {
if (!klass) {
if (env->exception())
klass = env->exception();
else {
klass = env->exception();
if (!klass) {
klass = find_top_level_const(env, "RuntimeError"_s);
message = new StringObject { "" };
}
Expand Down

0 comments on commit cd5975e

Please sign in to comment.