Both Scala and JavaScript feature exception handling, but Scala only allowsinstances of Throwable to be thrown/caught (which is enforced by the typechecker). JavaScript can throw/catch any type of value.
To reconcile the two worlds, Scala.js lifts all exceptions that are notinstances of Throwable inside js.JavaScriptException. This lifting works bothways.
Throwing an exception from Scala.js:
- Scala.js throws an instance of
js.JavaScriptException
-> JS catches the wrapped value - Scala.js throws an instance of
Throwable
-> JS catches it as is
Throwing an exception from JS:
- JS throws an instance of Scala.js’
Throwable
-> Scala.js catches it as is - JS throws something else -> Scala.js catches it wrapped in a
js.JavaScriptException