A Java program that throws exceptions recursively __j2se

Source: Internet
Author: User
    * * * Testexception.java * December 6, 2017 afternoon 2:37:47 * Copyright 2017 Fosun Financial.
     All Rights Reserved.
     * Don't ALTER or REMOVE COPYRIGHT notices or this FILE HEADER. * * Please contact Fosun Corporation or visit * www.fosun.com * If you need additional Informatio
     N or have any questions.
    
    * @author Flyer * @version 1.0/Package testfuxing; /** * Function Description * @version * @author Flyer December 6, 2017 afternoon 2:37:47 * @since 1.8/public class Te
    
        stexception {static int i = 0;
        public static void Main (String args[]) {Testdigui ();
            private static void Testdigui () {try {int t = i/0;
                catch (Exception e) {//new runtimeexception (e);
                    if (I < 3) {System.out.println ("before recursion:" + i);
                    i++; TesTdigui ();
                System.out.println ("Recursive:" + i);
                } i = 0;
            System.out.println ("Final execution:" + i);
 }
        }
    }


The output is:

Before recursion: 0
Before recursion: 1
Before recursion: 2
Last implemented: 0
After recursion: 0
Last implemented: 0
After recursion: 0
Last implemented: 0
After recursion: 0
Last implemented: 0

private static void TestExceptionOrder1 () {
int q[]= {1,0,8,19};
try {
for (int m:q) {
int t = 100/m;
System.out.println ("T:" + t);
}
}
catch (Exception e) {
System.out.println ("Final execution:" + E);
}
}

private static void TestExceptionOrder2 () {
int q[]= {1,0,8,19};

for (int m:q) {
try {
int t = 100/m;
System.out.println ("T:" + t);
}
catch (Exception e) {
E.printstacktrace ();
System.out.println ("Final execution:" + E);
}
}
}


The first function throws an exception and does not follow

t:100
Last implemented: Java.lang.ArithmeticException:/by zero

The second function throws an exception, which does not affect the subsequent execution of the

t:100
Last implemented: Java.lang.ArithmeticException:/by zero
T:12
T:5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.