一、try语句: try{//这里写可能出现异常的程序} catch(Exception e){//这里写如果出现异常怎么处理的程序} 二、throws语句 语法:函数方法() throws Exception {}三、try语句示 ...
一、try语句:
try{//这里写可能出现异常的程序}
catch(Exception e){//这里写如果出现异常怎么处理的程序}
二、throws语句
语法:函数方法() throws Exception {}
三、try语句示例:
import java.util.Scanner;public class Index{ public static void main(String[] args){ Scanner in = new Scanner(System.in); try{ System.out.println("请输入一个数字:"); int a = in.nextInt(); System.out.println("请输入一个数字:"); int b = in.nextInt(); int c = a%b; System.out.println("余数为:"+c); } catch(Exception e){ System.out.println("输入错误"); } //Exception 异常的意思 //后面的e 可以随便写,一遍写e,因为这个是一个对象 System.out.println("程序继续执行"); }}
原标题:JAVA 处理程序异常,(try、catch、finally),(thorws)
关键词:JAVA
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。