In Hades, everything can be an exception. There is a collection of standard exceptions (in std:exceptions) but nothing prevents you from throwing any object as an exception. This comes in quite handy when you want to handle multiple exceptions with very different error sources.
try-catch-else block
If you want to catch all exceptions, don't specify a type in the catch block.
Example
with client from mssql:clientwith server from std:httpwith console from std:iowith file from std:iovar connection object = client("Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password")
tryconnection.open()console.out("Connection opened!")connection.close()catch(object::SqlExceptione) //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!")endtry file.read("1.txt")catch(e)//ignoredendtryvar f object::File=file("2.txt")catch(object::FileNotFoundExceptione) console.out("File {} not found!".format(e.file))endlet srv =server(port=8080)srv.get("/:path", {req, res => let path =req.param["path"] tryif (file.exists(path)) let f = file.open(path) res.send(f.read()) else raise 404 endcatch(int status) res.status(status) else res.status(200) end})srv.start()
Code in an else block after a try-catch will be executed if the execution didn't fail.
Example
with console from std:iovar numbertry number =int(console.in())catch(e)console.out("Could not parse number")elseconsole.out("Number is {}".format(number))end
raise statement
The raise statement raises an exception.
Example
with exceptions from std:exceptionsfuncequals(a object, b object)if(a == null) raise exceptions.ArgumentNullException("{} is null".format(nameof(a)))elseif(b equals null) raise exceptions.ArgumentNullException("{} is null".format(nameof(b)) end put a == bend