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://www.codercto.com/courses/l/12.html
Developer's Guide to Social Programming
Mark D. Hawker / Addison-Wesley Professional / 2010-8-25 / USD 39.99
In The Developer's Guide to Social Programming, Mark Hawker shows developers how to build applications that integrate with the major social networking sites. Unlike competitive books that focus on a s......一起来看看 《Developer's Guide to Social Programming》 这本书的介绍吧!