public static final String getStackTrace(Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); return sw.toString(); }
怎样捕获Error,而不是Exception Error: URI=file:d:/200205230839.xml Line=5: Element type "Item111" must be declared.Error: URI=file:d:/200205230839.xml Line=5: The content of element type "Item" must match "(ItemName,UnitPrice,Quantity,Amount)".
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it. A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.
catch(Exception) {
System.out.println(e);
}
此时e就应该已经内部处理成为String类型的字符串数据了
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
Error: URI=file:d:/200205230839.xml Line=5: Element type "Item111" must be declared.Error: URI=file:d:/200205230839.xml Line=5: The content of element type "Item" must match "(ItemName,UnitPrice,Quantity,Amount)".