try {
System.out.println(1 / 0);//会抛出ArithmeticException
System.out.println(new int[] {}[0]);//会抛出ArrayIndexOutOfBoundsException
String str = null;
System.out.println(str.toString());//会抛出NullPointerException
} catch (ArithmeticException e) {
resultMap.put("errMsg", e.getMessage());
System.out.println("算术异常");
System.out.println(e.getMessage());
return ERROR;
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("数组下标越界异常");
return ERROR;
} catch (NullPointerException e) {
System.out.println("空指针异常");
return ERROR;
}
怎么用最简单的方法抛出一个手动的异常
最新推荐文章于 2024-01-17 17:36:31 发布