谨慎使用java的try catch

看看下面代码有何问题:

public static String writeFileToRemote(File file) throws Exception { PostMethod filePost = new PostMethod(Common.getInstance().getProperty( project/remoteFileServer) + /attach?action=upload); try { Part[] parts = new Part[4]; parts[0] = new StringPart(FILE_KIND,2); parts[1] = new StringPart(RECORD,true); parts[2] = new StringPart(FILE_KIND,2); parts[3] = new FilePart(FILE_PATH,file.getName(),file); filePost.setRequestEntity(new MultipartRequestEntity(parts,filePost.getParams())); HttpClient client = new HttpClient(); // 由于要上传的文件可能比较大,因此在此设置最大的连接超时时间 client.getHttpConnectionManager().getParams().setConnectionTimeout( 5000); int status = client.executeMethod(filePost); String file_path = ; if (status == HttpStatus.SC_OK) { // 从服务器响应的串中获得fileId String res = filePost.getResponseBodyAsString(); String retFileStr = retobj.fileId = ; res = res.substring(res.indexOf(retFileStr) + retFileStr.length()); file_path = res.substring(0,res.indexOf('')) .replace('|','/'); } file.delete(); return file_path; } catch (Exception e) { e.printStackTrace(); throw new Exception(写远程文件时出现异常!); } }
报错:

Caused by: java.lang.Exception: 写远程文件时出现异常! com.age.sale.view.tool.ImportTool.writeFileToRemote(ImportTool.java:112)
此时根本没法定位毛病!

因此,应当把try catch去掉,如果要catch,必须把报错信息记录下来!并显示到前台!由于查询日志是很麻烦的1件事情。

本文出自:ouyida3的csdn blog

2015.3.5

相关文章

文章浏览阅读8.4k次,点赞8次,收藏7次。SourceCodester Onl...
文章浏览阅读3.4k次,点赞46次,收藏51次。本文为大家介绍在...
文章浏览阅读1.1k次。- php是最优秀, 最原生的模板语言, 替代...
文章浏览阅读1.1k次,点赞18次,收藏15次。整理K8s网络相关笔...
文章浏览阅读1.2k次,点赞22次,收藏19次。此网络模型提供了...
文章浏览阅读1.1k次,点赞14次,收藏19次。当我们谈论网络安...