1. 程式人生 > 實用技巧 >13、Java 異常處理

13、Java 異常處理

1

退JavaJava

Javathrow JavaJRE

2

Javatrycatchfinallythrowthrows

3

IOException
ArithmeticExecption
NullPointerException
ClassCastException
SQLException
FileNotFoundException
NegativeArrayException
ArrayIndexOutOfBoundsException
SecturityException
EOFException
NumberFormatException
NoSuchMethodException

4

4.1trycatch
try{

//

}catch(ExceptionNamee1){

//Catch

}
4.2throws

使throws使throws調

4.3throw

throwtry

4.4

tryfinallyfinallytry使

使finally

finally{
//Codeforfinallyblock
}

5

Java Exceptionchecked exceptionRuntimeException

StringStringThrowableThrowable

packagejava.io;

publicclassIOExceptionextendsException{
staticfinallongserialVersionUID=7818375828146090155L;

publicIOException(){
super();
}

publicIOException(Stringmessage){
super(message);
}

publicIOException(Stringmessage,Throwablecause){
super(message,cause);
}

publicIOException(Throwablecause){
super(cause);
}
}

6

使

try{
//MaythrowException1,Exception2,orException3
}
catch(Exception1|Exception2|Throwablee){
//HandleExceptionshere
}