Java 实例 - 异常处理方法

Java 教程 · 2019-02-11 09:27:56

以下实例演示了使用 System 类的 System.err.println() 来展示异常的处理方法:

ExceptionDemo.java 文件

class ExceptionDemo { public static void main(String[] args) { try { throw new Exception("My Exception"); } catch (Exception e) { System.err.println("Caught Exception"); System.err.println("getMessage():" + e.getMessage()); System.err.println("getLocalizedMessage():" + e.getLocalizedMessage()); System.err.println("toString():" + e); System.err.println("printStackTrace():"); e.printStackTrace(); } } }

以上代码运行输出结果为:

Caught Exception
getMessage():My Exception
getLocalizedMessage():My Exception
toString():java.lang.Exception: My Exception
printStackTrace():
java.lang.Exception: My Exception
   at ExceptionDemo.main(ExceptionDemo.java:5)

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

MongoDB

MongoDB

Kristina Chodorow、Michael Dirolf / O'Reilly Media / 2010-9-24 / USD 39.99

Discover how MongoDB can help you manage a huMONGOus amount of data collected through your web application. This book covers the basic principles and advanced uses of this document-oriented database, ......一起来看看 《MongoDB》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具