java异常

66 阅读1分钟

image.png

常用方法

  • getMessage()获取异常信息,返回字符串。
  • toString() 获取异常类名和异常信息,返回字符串。
  • printStackTrace() 获取异常类名和异常信息,以及异常出现在程序中的位置。返回值void。
  • printStackTrace(PrintStream s) 通常用该方法将异常内容保存在日志文件中,以便查阅。

使用

try{}catch(Exception e){}finally{}

throws