| |
技术文档>>JAVA>>新手入门>>基础入门>查看文档 |
|
| |
- redirect printstacktrace() to a string |
|
| |
文章作者:未知 文章来源:水木森林 |
|
| |
查看:200次 录入:管理员--2007-11-17 |
|
| |
import java.io.*;
public class teststack2string { public static void main(string s[]){ try { // force an exception for demonstration purpose class.forname("unknown").newinstance(); } catch (exception e) { system.out.println(stack2string(e)); } }
static public string stack2string(exception e) { try { stringwriter sw = new stringwriter(); printwriter pw = new printwriter(sw); e.printstacktrace(pw); return "------" + sw.tostring() + "------"; } catch(exception e2) { return "bad stack2string"; } } }
|
|