💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
异常的概述: ![](https://box.kancloud.cn/3e264e6b9aa50640a9bb783b6efb46e5_904x246.png) try+catch处理异常: ~~~ package a1; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in =new Scanner(System.in); int a; int b; int c; try{ System.out.println("请输入a的值:"); a=in.nextInt(); System.out.println("请输入b的值:"); b=in.nextInt(); c=a%b; System.out.println("余数为"+c); }catch(Exception e){ System.out.println("输入有误"); } System.out.println("程序顺利进行中"); } } ~~~ ![](https://box.kancloud.cn/c74ada005b8645e5ca3f9047149debc3_232x130.png) 用throws处理异常 ![](https://box.kancloud.cn/cf9347e9c166569691928d2dffd24d20_911x371.png) ~~~ package a1; import java.util.Scanner; class A{ void a(){ int a,b,c; Scanner in =new Scanner(System.in); System.out.println("请输入a的值:"); a=in.nextInt(); System.out.println("请输入b的值:"); b=in.nextInt(); c=a%b; System.out.println("余数为"+c); } } public class Test1 { public static void main(String[] args) { A aa=new A(); try{ aa.a(); }catch(Exception e){ System.out.println("输入有误"); }finally{ System.out.println("顺利进行中..."); } } } ~~~ ![](https://box.kancloud.cn/d7ed8e9e802bfea0291c7e68bb5c39fc_214x129.png) finally ![](https://box.kancloud.cn/782536a9363c464fc8af6de3301b3c3b_934x318.png)