Exception handling
Exception handling
Crystal's way to do error handling is by raising and rescuing exceptions.
Raising exception
You raise exceptions by invoking a top-level raise
method. Unlike other keywords, raise
is a regular method with two overloads: one accepting a String and another accepting an Exception instance:
raise "OH NO!" raise Exception.new("Some error")
The String version just creates a new 登录查看完整内容