try catch return

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;
}

}
發佈了287 篇原創文章 · 獲贊 6 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章