public reade AToB(Object obj) throws BussinessException {
try {
StringWriter writer = new StringWriter();
StringReader reader = new StringReader(writer.toString());
writer.close();
return reader;
} catch (Exception e) {
e.printStrackTrace();
}
}
这样就报无返回值错误
如果将catch语句改成catch (Exception e) {
throw new BussinessOperationException(e);
}
就不报错了。为什么?
try {
StringWriter writer = new StringWriter();
StringReader reader = new StringReader(writer.toString());
writer.close();
return reader;
} catch (Exception e) {
e.printStrackTrace();
}
}
这样就报无返回值错误
如果将catch语句改成catch (Exception e) {
throw new BussinessOperationException(e);
}
就不报错了。为什么?
e.printStrackTrace()和throw 不是一回事,一个是打印stract 一个是异常退出此方法。
StringWriter writer = null;
StringReader reader = null;
try {
writer = new StringWriter();
reader = new StringReader(writer.toString());
} catch (Exception e) {
e.printStrackTrace();
}finally{
return reader;
}
}
StringWriter writer = null;
StringReader reader = null;
try {
writer = new StringWriter();
reader = new StringReader(writer.toString());
} catch (Exception e) {
e.printStrackTrace();
}finally{
writer.close();
}
return reader;
}
throw new 一个异常对象,是终止代码执行了