Skip to content

Fix(?) try/catch #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions polymod/hscript/_internal/PolymodInterpEx.hx
Original file line number Diff line number Diff line change
Expand Up @@ -373,33 +373,30 @@ class PolymodInterpEx extends Interp
#else
var err = error;
#end
switch (err) {
case EScriptThrow(errValue):
// restore vars
restore(old);
inTry = oldTry;
// declare 'v'
declared.push({ n : n, old : locals.get(n) });
locals.set(n,{ r : errValue });
var v : Dynamic = expr(ecatch);
restore(old);
return v;
default:
throw err;
}
} catch( err : Dynamic ) {
// I can't handle this error the normal way because Stop is private GRAAAAA
if (Type.getEnumName(err) == "hscript.Interp.Stop") {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason here it's Interp but for me it would always be _Interp. I hope this doesn't mean it changes somehow.

// restore vars
restore(old);
inTry = oldTry;
// declare 'v'
declared.push({ n : n, old : locals.get(n) });
locals.set(n, { r : switch (err) {
case EScriptThrow(errValue): errValue;
default: error;
}});
var v : Dynamic = expr(ecatch);
restore(old);
return v;
} catch (error : Dynamic) {
var en = Type.getEnum(error);
if (en != null && en.getName() == "hscript._Interp.Stop") {
inTry = oldTry;
throw err;
throw error;
Copy link
Author

@NotHyper-474 NotHyper-474 Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently throws an error in the program itself, although we might want to use errorEx here instead? Or whatever way Polymod uses to handle errors.

}

// restore vars
restore(old);
inTry = oldTry;
// declare 'v'
declared.push({ n : n, old : locals.get(n) });
locals.set(n,{ r : err });
locals.set(n, { r : error });
var v : Dynamic = expr(ecatch);
restore(old);
return v;
Expand Down