一、系统自动抛出异常
当程序语句出现一些逻辑错误、主义错误或者类型转换错误时,系统会自动抛出异常
例一
public static void main(String[] args) {
int a = 5;
int b = 0;
System.out.println( a / b);
}
运行结果,系统会自动抛出ArithmeticException异常
Exception in thread "main" java.lang.ArithmeticException: / by zero
at io.renren.modules.sys.controller.SysUserController.main(SysUserController.java:154)
例二
public static void main(String[] args) {
String str = "abc";
System.out.println(Integer.parseInt(str));
}
运行结果,系统会抛出NumberFormatException异常
Exception in thread "main" java.lang.NumberFormatException: For input string: "abc"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at io.ren版权声明:本文为m0_54864585原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。