1.throws和throw的区别 throws使用在函数外,是编译时的异常,throw使用在函数内,是运行时的异常 使用方法 public int method(int[] arr) throws NullPointerException{} public int method(int[] arr){ if(arr==null){ throw new NullPointerException (“数组的引用不能为空”); } } throws 抛出的是异常类,可以抛出多个,用逗号隔开,thro
throws与throw throws是方法可能抛出异常的声明.(用在声明方法时,表示该方法可能要抛出异常)语法:[(修饰符)](返回值类型)(方法名)([参数列表])[throws(异常类)]{......} public void doA(int a) throws Exception1,Exception3{......} throw是语句抛出一个异常. 语法:throw (异常对象); throw e; public class Person {
public class Runtest { public static void main(String[] args) { // TODO Auto-generated method stub Test(); } public static int Test() { int x = 5; try { int num = x / 0; System.out.println(num); } catch (ArithmeticException e) { System.err.println("除