newExc

来源:1-7 Java 中的异常链

qq_霸气丶丶诠释一切_0

2016-07-23 15:09

newExc是什么意思?从哪里来的?好像没有定义过啊!!

写回答 关注

3回答

  • 霜之咏叹颂
    2016-07-23 23:28:27

    public class test_1 {

        public static void main(String[] args) {
            test_1 result = new test_1();
            result.deal2();
        }
        public class DIYException1 extends Exception {
            public DIYException1() {
            }
        }
        public class DIYException2 extends Exception {
            public DIYException2() {
            }
        }
        //自定义两种异常
        public void test() throws DIYException1 {
            throw new DIYException1();
        }
        //通过test(),抛出异常1
        public void deal1() throws DIYException2 {
            try {
                test();
            } catch (DIYException1 e) {
                System.out.println("error1");
                throw new DIYException2();
            }    
        }
        //检测到异常1抛出后,抛出异常2,并输出error1
        public void deal2() {
            try {
                deal1();
            } catch (DIYException2 e) {
                System.out.println("error2");
            }
        }
        //检测到异常2后,输出error2
    }

    .initCause()是Exception中封装好的一些方法

  • qq_霸气丶丶诠释一切_0
    2016-07-23 15:41:27

    newExc.initCause(e);是用来干什么的?

  • 半夜吹风
    2016-07-23 15:26:45

    新的RuntimeException就叫做newExc,文中有定义:RuntimeException newExc=new RuntimeException,新的newExc是用来接收上个文件传进来的异常的.


Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409770 学习 · 4341 问题

查看课程

相似问题