Код: Выделить всё
// this is the main thread
for await(const something of someAsyncIterator){
const worker=new Worker('worker.js',{type:'module'})
worker.onerror=()=>{
worker.terminate()
console.log('Error is handled, show must go on!')
}
console.log(`
Some other stuff is cycling on here
but the workers revolution is going to kill me
by throwing some error at my face! Save me!
`)
}
// this is worker.js
throw '*Evilishly laughing*'
// and this is what im getting in my console
error: Uncaught (in worker "") (in promise) "*Evilishly laughing*"
error: Uncaught (in promise) Error: Unhandled error in child worker.
at Worker.#pollControl (ext:runtime/11_workers.js:204:19)
at eventLoopTick (ext:core/01_core.js:178:7)
Press any key to continue . . .
Подробнее здесь: https://stackoverflow.com/questions/796 ... s-an-error
Мобильная версия