TechScript handles errors using two complementary mechanisms: structured exception handling (try / catch) for recoverable failures, and explicit panics (throw) for unrecoverable errors.
Use a try block to run code that might fail. If an error is raised, execution transitions to the catch block:
try:
data is fs.read("non_existent_file.json")
say "{data}"
catch error:
say "Failed to read file: {error}"
The caught error object provides structured failure details.
Use the throw keyword to manually signal a recoverable exception:
to divide(a, b):
if b == 0:
throw "Division by zero is not allowed"
return a / b
try:
result is divide(10, 0)
catch err:
say "Caught error: {err}"
When the runtime encounters a fatal state (such as out-of-bounds or stack overflow), it triggers a panic, which terminates execution safely.