try catch是干嘛的 在什么情况下使用 catch是否有多种写法
用来捕获异常,给你个例子
import java.io.*;
public class ExcepTest{
public static void main(String args[]){
try{
int a[] = new int[2];
System.out.println("Access element three :" + a[3]);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Exception thrown :" + e);
}
System.out.println("Out of the block");
}
}
try{
//代码块
}catch(){
//处理代码块的异常
}finally{
//无论怎么样都执行,除非程序结束了
}
捕获异常
https://blog.csdn.net/m0_64491107/article/details/122444009