zoukankan      html  css  js  c++  java
  • try catch finally 关闭流标准的写法

    平常开发中,都知道要在finlly里关闭流,但是有时finlly里代码不当,会引起另外的异常。 
    以下是看struts2源代码看到的,随手记录下。 
    有两点注意: 
    (1)判断流是否为空。 
    (2)filly里要捕获异常 

    Java代码  收藏代码
      1.         InputStream in = null;  
      2.         try {  
      3.             in = settingsUrl.openStream();  
      4.             settings.load(in);  
      5.         } catch (IOException e) {  
      6.             throw new StrutsException("Could not load " + name + ".properties:"  
      7.                     + e, e);  
      8.         } finally {  
      9.             if (in != null) {  
      10.                 try {  
      11.                     in.close();  
      12.                 } catch (IOException io) {  
      13. //log  
      14.                 }  
      15.             }  
      16.         }  
  • 相关阅读:
    认证-权限-频率组件
    视图组件
    序列化类
    解析模块
    异常模块
    响应模块分析
    请求模块分析
    cbv请求分析
    django中的restful规范
    web接口与restful规范
  • 原文地址:https://www.cnblogs.com/xujanus/p/5378363.html
Copyright © 2011-2022 走看看