Home > Java > javaTutorial > body text

Java example - chain test exception

黄舟
Release: 2017-02-04 10:07:57
Original
1213 people have browsed it

The following example demonstrates the use of multiple catches to handle chain test exceptions:

/*
 author by w3cschool.cc
 Main.java
 */public class Main{
   public static void main (String args[])throws Exception  {
      int n=20,result=0;
      try{
         result=n/0;
         System.out.println("结果为"+result);
      }
      catch(ArithmeticException ex){
         System.out.println("发算术异常: "+ex);
         try {
         throw new NumberFormatException();
         }
         catch(NumberFormatException ex1) {
            System.out.println("手动抛出链试异常 : "+ex1);
         }
      }
   }
   }
Copy after login

##The above code The running output result is:

发算术异常: java.lang.ArithmeticException: / by zero
手动抛出链试异常 : java.lang.NumberFormatException
Copy after login


##The above is the content of the Java instance-chain test exception, For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!