Language
Errors & Exceptions
Throwing, catching, and handling failures
Notch raises failures with throw and handles them with try / catch.
Quick reference
throw 'boom'
try
throw 'boom'
catch RuntimeException as e
print(e)
end
Throwing
throw raises a value as an error:
throw 'boom'
Catching
A try block runs its statements; a matching catch handles a thrown exception,
binding it to a name with as:
try
throw 'boom'
catch RuntimeException as e
print(e)
end
Exception types
Exception types resolve by their short name in throw, catch, and new without
an import:
throw IOException("disk gone")
Using an exception type as a plain value elsewhere still needs an import - see Java Interop.
See also
- Error Index for every diagnostic code Notch reports, with a cause and a fix for each. This page covers raising and handling errors in your own code; the index covers the errors Notch itself reports.
- Java Interop for how JVM types resolve, and for
nullhandling. - Control Flow for the surrounding statement forms.