/**
*给TextView添加点击事件故意抛出异常
*/
??textView.setOnClickListener(new OnClickListener() {
[email protected]
???public void onClick(View v) {
????// TODO Auto-generated method stub
????Main main = new Main();
????try {
?????main.add();
????} catch (Exception e) {
?????try {
/**
*将异常记录
*/
??????OutputStream out = mContext.openFileOutput("bug.txt",
??????????ExceptionTestActivity.this.MODE_APPEND);//如果没有该文件会自动创建
??????PrintStream ps = new PrintStream(out);
??????e.printStackTrace(ps);
try {
???FileInputStream fis = mContext.openFileInput("bug.txt");//没有该文件的时候会抛异常
???InputStreamReader isr = new InputStreamReader(fis);
???BufferedReader br = new BufferedReader(isr);
???StringBuilder sb = new StringBuilder();
???String line = null;
???while ((line = br.readLine()) != null) {
????sb.append(line);
???}
???fis.close();
???textView.setText(sb.toString());
??} catch (Exception e2) {
???e2.printStackTrace();
??}
?????} catch (FileNotFoundException e1) {
??????// TODO Auto-generated catch block
??????e1.printStackTrace();
?????}
????}
???}
??});