GSET
Language Guide

Error Handling

try/catch/finally and throw in GSET, with exact per-target output.

Implemented

try / catch / finally

try {
    result = 10 / 2
    print(result)
} catch e {
    print("error", e)
} finally {
    print("done")
}
TargetOutput
Pythontry: / except Exception as e: / finally:
JavaScripttry { … } catch (e) { … } finally {
Rubybegin / rescue => e / ensure / end

The JavaScript catch is brace-correct (regression-tested for duplicate }). Specifying an exception type uses it:

catch ValueError e {
    print(e)
}

Python receives except ValueError as e:.

throw / raise

if score < 0 {
    throw "invalid score"
}
TargetOutput
Python / Rubyraise "invalid score"
JavaScript / Javathrow "invalid score";

Target caveats

  • Python, JavaScript, Ruby: fully functional — catch, finally ordering, and exception propagation all follow the target's native semantics.
  • Java: the try/catch/finally block is emitted in Java syntax. Since GSET functions become static methods inside Main, keep exceptions within method bodies for now.
  • Go: Go has no try/catch — the emitter currently prints C-style try { … } which does not compile under go run. Prefer error-return style or keep try only for non-Go targets. Named-exception handling in Go is Planned.

On this page