Discuss / Java / 捕获异常

捕获异常

Topic source

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {    public static void main(String[] args) {        try {            System.out.println(Tro(-5));        } catch (Exception e) {            System.out.println("catched");            throw new IllegalArgumentException(e);        }    }    public static int Tro(int a){        if(a<0){            throw new IllegalArgumentException("参数为负");        }        return a;    }}


  • 1

Reply