Skip to content

Commit

Permalink
avmc_queue,reference,fwd: Unify exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Oct 22, 2023
1 parent e046084 commit 169f32f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
17 changes: 7 additions & 10 deletions asteria/fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,14 @@ invoke_ptc_aware(Reference& self, Global_Context& global, Reference_Stack&& stac
if(auto ptr = this->m_sptr.get())
return ptr->invoke_ptc_aware(self, global, ::std::move(stack)); // dynamic
}
catch(Runtime_Error& except) {
// Forward the exception.
throw;
}
catch(exception& stdex) {
auto known = dynamic_cast<Runtime_Error*>(&stdex);
if(known) {
// Forward the exception.
throw;
}
else {
// Replace the active exception.
Runtime_Error except(Runtime_Error::M_format(), "$1", stdex);
throw except;
}
// Replace the active exception.
Runtime_Error except(Runtime_Error::M_format(), "$1", stdex);
throw except;
}

throw Runtime_Error(Runtime_Error::M_format(),
Expand Down
21 changes: 9 additions & 12 deletions asteria/llds/avmc_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,16 @@ execute(Executive_Context& ctx) const
status = qnode->pv_meta->exec(ctx, qnode);
break;
}
catch(Runtime_Error& except) {
// Modify the exception in place and rethrow it without copying it.
except.push_frame_plain(qnode->pv_meta->sloc);
throw;
}
catch(exception& stdex) {
auto known = dynamic_cast<Runtime_Error*>(&stdex);
if(known) {
// Modify the exception in place and rethrow it without copying it.
known->push_frame_plain(qnode->pv_meta->sloc);
throw;
}
else {
// Replace the active exception.
Runtime_Error except(Runtime_Error::M_format(), "$1", stdex);
except.push_frame_plain(qnode->pv_meta->sloc);
throw except;
}
// Replace the active exception.
Runtime_Error except(Runtime_Error::M_format(), "$1", stdex);
except.push_frame_plain(qnode->pv_meta->sloc);
throw except;
}
}

Expand Down
5 changes: 2 additions & 3 deletions asteria/runtime/air_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,9 +1199,8 @@ solidify(AVMC_Queue& queue) const
return status;
}
else
throw Runtime_Error(Runtime_Error::M_throw(),
format_string("Range value not iterable (value `$1`)", range),
sp.sloc_init);
throw Runtime_Error(Runtime_Error::M_assert(), sp.sloc_init,
format_string("Range value not iterable (value `$1`)", range));
}

// Uparam
Expand Down

0 comments on commit 169f32f

Please sign in to comment.