Java异常处理-异常的概念

程序在执行过程中,出现意外,我们专业属于叫做出现了异常;类似开车路上出了交通事故;

package com.java1234.chap01.sec01;
 
public class ExceptionDemo {
 
    public static void main(String[] args) {
        String str="123";
        int a=Integer.parseInt(str);
        System.out.println(a);
    }
}

这个代码执行是没问题的,运行输出:

123

假如我们把123改成123a

package com.java1234.chap01.sec01;
 
public class ExceptionDemo {
 
    public static void main(String[] args) {
        String str="123a";
        int a=Integer.parseInt(str);
        System.out.println(a);
    }
}

猜你喜欢

转载自www.cnblogs.com/xyg-zyx/p/9833370.html