Is there a rescript-core pattern match for javascript exceptions?

because rescript-core aims to replace Js.Exn with Error?

I’m not sure but I think Js.Exn.Error is not actually a type but some kind of built in matcher which just shows “exn” in the mouse hover.

old and new mix below

try {
  throw()
} catch {
| Js.Exn.Error(e) => Console.log(Error.message(e))
}

It’s the same thing, just aliased: https://github.com/rescript-association/rescript-core/blob/0e88d7e115ab0630b672445a31e8ccda82342222/src/RescriptCore.res#L59

So when you have RescriptCore opened, it should just be

try {
  throw()
} catch {
| Exn.Error(e) => Console.log(Error.message(e))
}
1 Like

I guess that is consistent, chop off the Js., but is that really a type or just a lang construct built into the compiler? Meaning you could replace Exn.Error(e) with Potato(e) as long as the compiler knows what to do.

Yes

But in rescript-core it’s just an alias to Js https://github.com/rescript-association/rescript-core/blob/0e88d7e115ab0630b672445a31e8ccda82342222/src/RescriptCore.res#L59

1 Like

It is actually a predefined exception called JsError. But it is not exposed itself and Exn.Error is also private, so it cannot be aliased to Potato I am afraid.