当前位置: 首页 > news >正文

行业网站建设方案网站开发专业是干嘛的

行业网站建设方案,网站开发专业是干嘛的,百度seo公司有哪些,浙江网站建设推广公司找哪家有一点很重要,即你要时刻询问子句如果异常发生了,所有东西能被正确清理码?,尽管大多数情况下时非常安全的,但涉及到构造器时,问题出现了,构造器会把对象设置成安全的初始状态,但还会又别的动作,比如打开一个文件,这样的动作只有在对象使用完毕并且用户调用了特殊的…  有一点很重要,即你要时刻询问子句如果异常发生了,所有东西能被正确清理码?,尽管大多数情况下时非常安全的,但涉及到构造器时,问题出现了,构造器会把对象设置成安全的初始状态,但还会又别的动作,比如打开一个文件,这样的动作只有在对象使用完毕并且用户调用了特殊的清理方法之后才能得以清理,如果在构造器内抛出了异常,这些行为也许就不能正常工作了,这意味着在编写构造器时要格外细心.   用finally也许可以解决问起,但问题并非如此简单,因为finally会每次都执行清理操作,如果构造器在执行过程中半途而废,也许该对象的某部分还没有创建成功就要被清理,这又会抛出新的异常(.close()也会抛出异常)  1.构造器抛出异常要格外注意清理方法是否有必要调用,如果方法恰当,直接向上层抛出的确能简化编程 package exceptions; //: exceptions/InputFile.java // Paying attention to exceptions in constructors. import java.io.*;public class InputFile {private BufferedReader in;public InputFile(String fname) throws Exception {try {in new BufferedReader(new FileReader(fname));// Other code that might throw exceptions} catch(FileNotFoundException e) {System.out.println(Could not open fname);// Wasnt open, so dont close it //如果没有打开文件就不需要关闭throw e;} catch(Exception e) {// All other exceptions must close it 如果时其它异常则必须关闭文件try { //in.close()也可能抛出异常,所有要放到try块里面in.close();} catch(IOException e2) {System.out.println(in.close() unsuccessful);}throw e; // Rethrow} finally { //由于finally总会被执行,如果在这里关闭文件则文件刚打开还没开始使用就关闭了// Dont close it here!!!}}public String getLine() {String s;try {s in.readLine();} catch(IOException e) { //这这异常已被捕获,因此getLine不会抛出任何异常throw new RuntimeException(readLine() failed);//重新抛出新的异常到上层环境,有时会简化编程}return s;}public void dispose() {try {in.close();System.out.println(dispose() successful);} catch(IOException e2) {throw new RuntimeException(in.close() failed);}} } ///:~ 2.对于在构造器阶段可能抛出的异常,并且要求清理的,最安全的使用方法时使用嵌套的try子句, package exceptions; //: exceptions/Cleanup.java // Guaranteeing proper cleanup of a resource.public class Cleanup {public static void main(String[] args) {try {InputFile in new InputFile(Cleanup.java);try {String s;int i 1;while((s in.getLine()) ! null); // Perform line-by-line processing here...} catch(Exception e) {//这里捕捉的时getLine()方法重新抛出的异常System.out.println(Caught Exception in main);e.printStackTrace(System.out);} finally { //如果构造成功,则一定会执行in.dispose()清理in.dispose();}} catch(Exception e) { //InputFile对象在自己的try语句块优先,因此构造失败会进入这里,而不会执行内部的try块的in.colse()System.out.println(InputFile construction failed);}} } /* Output: dispose() successful *///:~   3. 这种通用的清理惯用法在构造器不跑出任何异常时也应该应用,其基本规则时:在需要清理的对象之后,立即进入一个try-finally语句块. //基本上,你应该仔细考虑所有的可能细节,例如本例的dispose()如果可以抛出异常,那么就需要额外的try语句块package exceptions; //: exceptions/CleanupIdiom.java // Each disposable object must be followed by a try-finallyclass NeedsCleanup { // Construction cant failprivate static long counter 1;private final long id counter;public void dispose() {System.out.println(NeedsCleanup id disposed);} }class ConstructionException extends Exception {}class NeedsCleanup2 extends NeedsCleanup {// Construction can fail:public NeedsCleanup2() throws ConstructionException {} }public class CleanupIdiom {public static void main(String[] args) {// Section 1:NeedsCleanup nc1 new NeedsCleanup();try {// ...} finally {nc1.dispose();}// Section 2:// If construction cannot fail you can group objects:// nc5 constructor 如果对象构造不能失败就不需要任何catch//不能失败的对象构造器对象可以群众在一起NeedsCleanup nc2 new NeedsCleanup();NeedsCleanup nc3 new NeedsCleanup();try {// ...} finally {nc3.dispose(); // Reverse order of construction nc2.dispose();}// Section 3:// If construction can fail you must guard each one:try {NeedsCleanup2 nc4 new NeedsCleanup2();try {NeedsCleanup2 nc5 new NeedsCleanup2();try { //如果nc5对象构造失败则会调用try块清理,否则永不调用// ...} finally {nc5.dispose();}} catch(ConstructionException e) { System.out.println(e);} finally {nc4.dispose();}} catch(ConstructionException e) { // nc4 constructorSystem.out.println(e);}} } /* Output: NeedsCleanup 1 disposed NeedsCleanup 3 disposed NeedsCleanup 2 disposed NeedsCleanup 5 disposed NeedsCleanup 4 disposed *///:~  转载于:https://www.cnblogs.com/jiangfeilong/p/10303179.html
http://www.sadfv.cn/news/292287/

相关文章:

  • 唐山seo设计网站网页设计公司兴田德润在哪儿
  • 有哪些可以免费推广的网站宁波最专业的seo公司
  • 高端网站建设费用预算汕头网站搭建多少钱
  • 赣州专业网站推广怎么在自己的网站上做漂浮链接
  • tp框架做响应式网站直播网站开发步骤
  • 自己做的网站如何让别的网可以查看望城经济建设开区门户网站
  • 微信上发的链接网站怎么做的网站建设合同书保密条款
  • 网站制作论文题目建站教程视频下载
  • 南阳微网站建设智慧景区网站服务建设
  • 网站的项目建设周期网址域名查询
  • 网站建设管理工作情况的通报网站开发分前台后台
  • tp框架做视频网站织梦网站搬家数据库
  • 兰州网站seo优化公司怎么在小程序里开店铺
  • 北京营销网站建设设计学校网站管理
  • 太湖手机网站建设做视频能赚钱的网站
  • ip做网站大连天健网大连
  • 福州闽侯网站建设高县网站建设
  • 做网站网站的人是怎么被抓的网络服务的工具
  • 网站psd设计稿免费虚拟机
  • 国外网站怎么做济南企业营销型网站建设价格
  • 如何提高网站的收录率和收录量云南省建设测量员注册网站
  • 搭建影视网站企业品牌推广策略
  • 三合一商城网站上位机软件开发工具
  • 洪梅仿做网站百度爱采购网站官网
  • 提供网站建设设计外包wordpress付费插件网站
  • 常州微信网站建设教程建设银行网上流览网站
  • 网站速度诊断 慢搭建网站要多久
  • 做pc端网站行业现状解决网站提示有风险
  • 网站的宣传方法有哪些wordpress安装的要求
  • 5000元网站seo推广品牌建设是指