Syntax Lookup

Enter some language construct you want to know more about.

throw()

This is the throw() function.

throw() raises the given exception. Execution stops unless a surrounding try/catch block catches it.

ReScriptJS Output
exception MyException(string)

let result = try {
  throw(MyException("Out of milk"))
} catch {
| MyException(message) => "Caught exception: " ++ message
}

To throw a JavaScript Error instead of a ReScript exception, use JsError.throwWithMessage or the other functions in JsError.

References