Try
The syntax for Lua error handling in a common form.
try func 1, 2, 3catch err print yue.traceback err
success, result = try func 1, 2, 3catch err yue.traceback err
try func 1, 2, 3catch err print yue.traceback err
success, result = try func 1, 2, 3
try print "trying" func 1, 2, 3
-- working with if assignment patternif success, result := try func 1, 2, 3catch err print yue.traceback err print resulttry func 1, 2, 3catch err print yue.traceback err
success, result = try func 1, 2, 3catch err yue.traceback err
try func 1, 2, 3catch err print yue.traceback err
success, result = try func 1, 2, 3
try print "trying" func 1, 2, 3
-- working with if assignment patternif success, result := try func 1, 2, 3catch err print yue.traceback err print resulttry? is a simplified use for error handling syntax that omit the boolean status from the try statement, and it will return the result from the try block when success, return nil instead of error object otherwise.
a, b, c = try? func!
-- with nil coalescing operatora = (try? func!) ?? "default"
-- as function argumentf try? func!
-- with catch blockf try? print 123 func!catch e print e ea, b, c = try? func!
-- with nil coalescing operatora = (try? func!) ?? "default"
-- as function argumentf try? func!
-- with catch blockf try? print 123 func!catch e print e e