Source: src/hql/transpiler/pipeline/transform/try-catch.ts, src/hql/transpiler/syntax/conditional.ts
HQL provides structured error handling via try/catch/finally/throw. All error handling forms are expressions that return values, achieved through automatic IIFE wrapping.
try/catch/finally with expression semantics (returns a value)try blocks usable anywhere an expression is expected(catch e ...) or parameterless (catch ...)await if body contains awaityield* if body contains yield(throw expr) for throwing errors;; try/catch as expression
(let result (try
(JSON.parse input)
(catch e "default")))
;; try/catch/finally
(try
(open-connection)
(send-data payload)
(catch e (log-error e))
(finally (close-connection)))
;; throw
(throw (new Error "something went wrong"))
| Form | Example |
|---|---|
| try-only | (try body...) |
| try + catch | (try body... (catch e handler...)) |
| try + finally | (try body... (finally cleanup...)) |
| try + catch + finally | (try body... (catch e handler...) (finally cleanup...)) |
| throw | (throw expr) |