抛出错误

  1. throw new Error('错误信息') //抛出错误

捕获错误

  1. try{
  2. console.log('如果内部代码发生错误将执行catch')
  3. }
  4. catch{
  5. console.log('抛出错误')
  6. }
  7. finally{
  8. console.log('无论try和catch是否报错finally都会执行,及时try出错,catch里面有return,finally还是会执行')
  9. }