How do I handle errors thrown from the browser runtime?
In main.js, I have some JS code which may throw an error. To test error handling from Scheme, I just throw an error myself:
navigator: {
requestWakeLock: () => {
// navigator.wakeLock.request("screen")
throw new Error('FAIL');
}
In dom/modules/navigator.scm:
(define-foreign request-wake-lock
"navigator" "requestWakeLock"
-> (ref extern))
In main.scm, I wrap the code which I expect to throw an error in with-exception-handler according to the hoot manual (I think):
(with-exception-handler
(lambda (exn)
(format (current-error-port)
"Wake Lock could not be set: ~s\n" exn)
#f)
(lambda () (await (request-wake-lock))))
In the browser console, I see:
Uncaught (in promise) Error: FAIL
requestWakeLock http://localhost:8088/main.js:82
call http://localhost:8088/reflect.js:380
call http://localhost:8088/reflect.js:118
#init_module http://localhost:8088/reflect.js:280
load_main http://localhost:8088/reflect.js:285
async* http://localhost:8088/main.js:3
EventListener.handleEvent* http://localhost:8088/main.js:1
main.js:82:19
<anonymous> http://localhost:8088/main.js:118
AsyncFunctionThrow self-hosted:804
(Async: async)
<anonymous> http://localhost:8088/main.js:1
which is the same error I get if I don’t wrap it in with-exception-handler:
(await (request-wake-lock))
Advice very much appreciated!
Thank you,
Joseph