异常的处理方式

1.遇到问题不进行具体处理,而是继续抛给调用者 (throw,throws)

抛出异常有三种形式,一是 throw,一个 throws,还有一种系统自动抛异常。

public static void main(String[] args) { 
 String s = "abc"; 
 if(s.equals("abc")) { 
 throw new NumberFormatException(); 
 } else { 
 System.out.println(s); 
 } 
} 
int div(int a,int b) throws Exception{
return a/b;}

2.try catch 捕获异常针对性处理方式

posted @ 2024-03-17 15:32  阿飞藏泪  阅读(1)  评论(0编辑  收藏  举报
1 2 3
4