Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throw native JS exception in Scala.js

Scala's throw expects a Throwable, which js.Error is not.

I need to re-throw a JS error that was provided to me by a third party JS lib. Said lib will then catch that re-thrown error again and do something about it.

I could write a one-line npm module in JS: module.exports = function (e) { throw e; }, and add it to my npmDependencies, but I was wondering if there is a better solution for this.

like image 695
Nikita Avatar asked Oct 19 '25 04:10

Nikita


1 Answers

You have to wrap the JS error in a js.JavaScriptException:

import scala.scalajs.js

throw js.JavaScriptException(e)
like image 132
sjrd Avatar answered Oct 21 '25 03:10

sjrd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!