Why doesn't try {} catch () {} execute?

try{
  setTimeout(()=>{
      d //
  })
  //c; // c is undefined  
}catch(e){
 console.log(e.message)
}
Apr.21,2022

because setTimeout is asynchronous, to get an exception in an asynchronous operation, you need to write the try catch in the asynchronous operation.


how can synchronous syntax catch asynchronous errors


   setTimeout(()=>{
      console.log('d')
    })

cannot output a single

of d.
Menu