A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
                //建立ArrayList<Integer>对象
                ArrayList<Integer> list = new ArrayList<Integer>();

                String str ="wo yao jin hei ma!";
               
                //用放射调用list的方法
                Method[] method =list.getClass().getMethods();
                System.out.println(method[0].invoke(list, str));
                System.out.println(list);
        }

像这种情况,在面试的时候可以直接抛出异常吗?还是要try catch处理

1 个回复

倒序浏览
主函数 不要在抛了。    主函数应该处理掉所以的异常,如果主函数选择抛异常的话,一旦出现异常,程序将终止运行!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马