function do1() {
  throw {error: 'Something went wrong'}
}
async function test() {
  return new Promise(res => {
    setTimeout(() => {
      do1()
      console.log('After throw')
      res()
    }, 2000)
  })
}
async function main() {
  try {
    await test()
  } catch (error) {
    console.log('Error catched: ', error)
  }
  console.log('Finally')
}
main()const delay = ms => new Promise(resolve => setTimeout(() => resolve(), ms));
(async function() {
  try {
    await delay(2000);
    do1();
  } catch (error) {
    console.log('Error catched: ', error)
  } finally {
    console.log('Finally')
  }
})(); 
  
  process.on('uncaughtException', err => {
    console.error(err)
    process.exit()
})