multiplecatch.java

来自「有关java编程的课件及附上有关的源代码」· Java 代码 · 共 69 行

JAVA
69
字号
/*
 * (c)2005 Aptech Limited
 * All Rights Reserved
 */

/**
  * This class demonstrate the multiple catch statements.
  *
  * @version 1.0 2 June 2005
  * @author Michael
  */
package SG5.Example3;

class NumberException {


    /** Constructor. */
    protected NumberException() {
        }

     /** This method divides the number by zero.
       * @param number is used to store the args value.
       */
    public void test(String[] number) {

     try {

            /* Variable declaration for storing the vaue of args. */
            String num = number[0];
            int numValue = Integer.parseInt(num);

            System.out.println("The square is: " + numValue * numValue);

        /* Catching the array exxeptions. */
        } catch (ArrayIndexOutOfBoundsException ne) {

            System.out.println("No arguments given!");

        /* Catching the number format ecxeptions. */
        } catch (NumberFormatException nb) {

            System.out.println("Not a number!");
        }
    }
}

/**
  * This is a main class.
  */

class MultipleCatch {

    /** Constructor. */
    protected MultipleCatch() {
    }

    /**
     * Sole entry point to the class and application.
     * @param args Array of String arguments.
     */

    public static void main(String[] args) {

        NumberException obj = new NumberException();
        obj.test(args);

 }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?