try catch return

1861 ワード

package com.java.test;

import java.util.ArrayList;
import java.util.List;

public class TestReturn {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println( testt5());
	}
	
	 public static int testt() {  
         int x = 99;  
         try {  
             return x;  
         }finally {  
             x = 8;  
         }  
     }  
	 
	    public static int testt1() {  
            int x = 99;  
            try {  
                return x;  
            }catch(Exception e){  
                return x;  
            }finally {  
                x = 8;  
            }  
        }  
	    
	    public static int testt3() {  
            int x = 99;  
            try {  
                return x/0;  
            }catch(Exception e){  
                  System.out.println(e.getMessage());
            }finally {  
                x = 8;  
            }  
            return x;  
        }  
	    
	    static int x = 99;  
	    public static int testt4() {  
	        try {  
	            return x;  
	        } catch (Exception e) {  
	        } finally {  
	            x = 8;  
	        }  
	        return x;  
	    }  
	    
	    public static List testt5() {  
	        List list = new ArrayList();  
	        list.add("a");  
	        try {  
	            return list;  
	        } catch (Exception e) {  
	        } finally {  
	            list.add("b");  
	        }  
	        return list;  
	    }  

}