1、避免过多使用Finally块,有时候可以考虑using等语句,能达到相同效果;

2、应捕获可以预见的异常,避免捕获所有异常(如Exception,SystemException);

3、当异常无法修复时,回滚部分完成的操作;

4、隐藏实现细节,例如:

  catch(FileNotFoundException e) { throw new NameNotFoundException(name, e); }

  这里就不会显示FileNotFoundException了。

相关文章:

  • 2021-12-27
  • 2021-07-26
  • 2021-12-02
  • 2021-12-10
  • 2022-02-08
  • 2021-10-25
猜你喜欢
  • 2021-10-24
  • 2021-07-27
  • 2021-09-02
  • 2021-04-18
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案