关于上班这件事
public void myMethod() throws IOException{
// do something
}
public void myMethod() throws Exception1, Exception2, ..., ExceptionN{
// do something
}
FileNotFoundExceptionDemo ex=new FileNotFoundExceptionDemo("File Not Exist");
throw ex;
throw new FileNotFoundException("File Not Exist");
try{
statements;
}
catch(Exception1 ex1){
handler for ex1;
}
catch(Exception2 ex2){
handler for ex2;
}
...
catch(ExceptionN exN){
handler for exN;
}
main method{
...
try{
...
invoke method1;
statement1;
}
catch(Exception1 ex1){
process ex1;
}
statement2;
}
void p2() throws IOException{
// ...
}
void p1(){
try{
p2();
}
catch(IOException ex){
//...
}
}
void p2() throws IOException{
//...
}
void p1() throws IOException{
p2();
}
try{
statements;
}
catch(Exception ex){
perform operations before exits;
throw ex;
}
try{
statement;
}
catch(Exception ex){
handling ex;
}
finally{
finalstatements;
}
public class FinallyDemo{
public static void main( String [] args ){
java.io.PrintWriter output = null;
try{
output = new java.io.PrintWriter( "text.txt" );
output.println( "Welcome to Java" );
}
catch( java.io.IOException ex ){
ex.printStackTrace();
}
finally{
if( output != null )
output.close();
}
System.out.println( "End of program" );
}
}
Case 1: 无异常
try{
statements;
}
catch( Exception ex){
handling ex;
}
finally{
finalStatements;
}
Next statements;
Case 2: 抛出可捕获的异常
try{
statements1;
statements2;
statements3;
}
catch( Exception1 ex){
handling ex;
}
finally{
finalStatements;
}
Next statements;
Case 3: 无法处理异常,继续抛出
try{
statements1;
statements2;
statements3;
}
catch( Exception1 ex){
handling ex;
}
catch( Exception2 ex ){
handling ex;
throw ex;
}
finally{
finalStatements;
}
Next statements;
finally之前有return语句怎么办?