Add exception handlers in places where scripts are invoked. This should lead to slightly nicer error messages.

This commit is contained in:
Twan van Laarhoven
2020-05-22 00:30:18 +02:00
parent 8b91cd8804
commit c9c7a958ae
5 changed files with 38 additions and 14 deletions
+10 -2
View File
@@ -44,8 +44,16 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) {
ctx.setVariable(SCRIPT_VAR_styling, to_script(&set.stylingDataFor(*stylesheet)));
try {
// perform init scripts, don't use a scope, variables stay bound in the context
set.game ->init_script.invoke(ctx, false);
stylesheet->init_script.invoke(ctx, false);
try {
set.game ->init_script.invoke(ctx, false);
} catch (const ScriptError& e) {
handle_error(ScriptError(e.what() + _("\n in init script for game ") + set.game->name()));
}
try {
stylesheet->init_script.invoke(ctx, false);
} catch (const ScriptError& e) {
handle_error(ScriptError(e.what() + _("\n in init script for stylesheet ") + stylesheet->name()));
}
} catch (const Error& e) {
handle_error(e);
}