Exception handling
try-catch-else block
try-catch-else blockExample
with client from mssql:client
with server from std:http
with console from std:io
with file from std:io
var connection object = client("Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password")
try
connection.open()
console.out("Connection opened!")
connection.close()
catch(object::SqlException e) //here, an SqlException is caught
console.out("SqlException was caught!")
catch(e) //in the case that any other exception was raised, this block is invoked
console.out("An unknown exception was caught!")
end
try
file.read("1.txt")
catch(e)
//ignored
end
try
var f object::File = file("2.txt")
catch(object::FileNotFoundException e)
console.out("File {} not found!".format(e.file))
end
let srv = server(port=8080)
srv.get("/:path", {req, res =>
let path = req.param["path"]
try
if (file.exists(path))
let f = file.open(path)
res.send(f.read())
else
raise 404
end
catch(int status)
res.status(status)
else
res.status(200)
end
})
srv.start()Example
raise statement
raise statementExample
Last updated