异常处理

Posted Jeesite 2.0

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常处理相关的知识,希望对你有一定的参考价值。

 

package com.chinadays.learn;

public class TestException {

    public static void main(String[] args) {
        try {
            int i = 0;

            System.out.println(10 / i);
        } catch (Exception e) {
            System.out.println("TestException:" + e.toString());
            System.out.println("Test:" + e.getMessage());
            e.printStackTrace();

        }
    }
}

 

异常处理  输出堆栈内的信息:

 

TestException:java.lang.ArithmeticException: / by zero
Test:/ by zero
java.lang.ArithmeticException: / by zero
at com.chinadays.learn.TestException.main(TestException.java:9)

以上是关于异常处理的主要内容,如果未能解决你的问题,请参考以下文章

使用片段中的处理程序时出现非法状态异常

Java异常处理机制

java 反射代码片段

java.util.MissingResourceException: Can't find bundle for base name init, locale zh_CN问题的处理(代码片段

使用实体框架迁移时 SQL Server 连接抛出异常 - 添加代码片段

片段中的Android致命异常