package com.hao.test;
public class test2 {
static String cc="this is a test2.";
public static String getinfo() throws Exception{
if (true) {
throw new Exception();
}
return cc;
}
}
主程序:
public class Test extends Activity implements OnClickListener {
private TextView textView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
try {
test2.getinfo();//在此调用,出现异常,所以执行catch中的程序。
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
textView1.setText("因为抛出异常,所以这里用try捕获,catch 处理此异常 ");
}
handler();
// settext();
}