Java中getMessage()和printStackTrace方法
生活随笔
收集整理的這篇文章主要介紹了
Java中getMessage()和printStackTrace方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public?class?ExceptionTest07{public?static?void?main(String[]?args){try{FileInputStream?fis?=?new?FileInputStream("c:/abc.txt");//JVM為我們執行了一下這段代碼//FileNotFoundException?e?=?new?FileNotFoundException("c:\abc.txt?(系統找不到指定的文件。)");}catch(FileNotFoundException?e){//打印異常堆棧信息.//一般情況下都會使用該方式去調試程序.//e.printStackTrace();/*java.io.FileNotFoundException:?c:\abc.txt?(系統找不到指定的文件。)at?java.io.FileInputStream.open(Native?Method)at?java.io.FileInputStream.<init>(FileInputStream.java:106)at?java.io.FileInputStream.<init>(FileInputStream.java:66)at?ExceptionTest07.main(ExceptionTest07.java:13)*/String?msg?=?e.getMessage();//e.getMassage的來源于JVM為我們執行了一下這段代碼,FileNotFoundException?e?=?new?FileNotFoundException("c:\abc.txt?(系統找不到指定的文件。)");System.out.println(msg);?//c:\abc.txt?(系統找不到指定的文件。)}//這段代碼會執行.System.out.println("ABC");}
}
轉載于:https://blog.51cto.com/hangtiangazi/1661698
總結
以上是生活随笔為你收集整理的Java中getMessage()和printStackTrace方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你不一定懂的cpu显示信息
- 下一篇: 注意Java陷阱