Error Handling & Exceptions
Djazair uses structured exception handling with try, catch, finally, and throw to gracefully handle runtime errors and guarantee resource cleanup.
Try, Catch, Finally
djazair
try
let divisor = 0
if divisor == 0
throw "Division by zero is not permitted"
end
catch err
print("Caught error: ${err}")
finally
print("Cleanup logic executed unconditionally")
end
# => Caught error: Division by zero is not permitted
# => Cleanup logic executed unconditionally
Nested Exceptions & Rethrowing
Exceptions propagate up the call stack until caught. You can catch an error, perform logging, and rethrow:
djazair
fn processFile(filename)
try
# Attempt operation
throw "FileNotFound: ${filename}"
catch e
print("Log: failed to process ${filename}")
throw e # Rethrow error to caller
end
end
try
processFile("config.json")
catch e
print("Top-level handler received: ${e}")
end