JS Exception

Catching a JS Exception in Rescript

@new external make: float => Js.Array2.t<int> = "Array"
try {
  let a = make(111111111111111111111111111.1)
} catch {
| Js.Exn.Error(obj) =>
  switch Js.Exn.message(obj) {
  | Some(e) => Js.log(e)
  | None => Js.log("No message")
  }
}
// Invalid array length

Raise a JS Exception from Rescript

Raising from Rescript site
let myTest = () => {
  Js.Exn.raiseError("Hello!")
}
Catching it from JS side
// after importing `myTest`...
try {
  myTest()
} catch (e) {
  console.log(e.message) // "Hello!"
}