Rugo uses try / or for error handling. Three levels of control.
try alone returns nil on failure:
result = try `nonexistent_command`
# result is nil — script continuesFire and forget:
try nonexistent_command
puts "still running"try ... or default returns a fallback on failure:
hostname = try `hostname` or "localhost"
puts hostnameuse "conv"
port = try conv.to_i("not_a_number") or 8080
puts port # 8080try ... or err ... end runs a block on failure. The error message is available as the named variable. The last expression in the block becomes the result.
data = try `cat /missing/file` or err
puts "Error: #{err}"
"fallback"
end
puts data # fallbackShell commands work with try too:
result = try nonexistent_command or "default"
puts result # defaultUse raise to signal errors from your own code. It works like Go's panic() under the hood and can be caught with try/or:
raise("something went wrong")Paren-free syntax works too:
raise "something went wrong"Use raise in functions to validate inputs:
def greet(name)
if name == nil
raise "name is required"
end
return "Hello, " + name
end
msg = try greet(nil) or err
puts "Error: " + err
"Hello, stranger"
end
puts msg # Hello, strangerCalled without arguments, raise uses a default message:
result = try raise() or err
err
end
puts result # runtime errorThat's it! You now know enough Rugo to build real scripts. See the examples/ directory for more.