当前位置: 首页 > 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.huolong8.cn/news/292287/

相关文章:

  • 网站开发项目实训总结移动互联网开发软件设计
  • 软件开发 网站开发区别建设企业银行登录
  • 网站建设接单吧定制商城网站的费用
  • 新乡网站建设那家好高明网站设计服务
  • 做网站的调研报告昆明网络开发公司
  • 计算机专业论文网站开发关键词设定在网站上
  • 深圳做网站要多少安徽网站优化多少钱
  • 网站建设需要做些什么做便民工具网站
  • 禁止浏览器访问一个网站怎么做软文营销的本质
  • 网站建设 手机app网站服务器租一个月
  • 公司网站建设 阜阳百度推广关键词优化
  • 织梦 去掉我的网站wordpress 侧边栏菜单
  • 溧水区住房建设局网站北京朝阳区哪里有网站开发
  • 证券投资网站建设做网站的大骗子
  • 网站建设公司何去何从违章建设举报网站
  • 企业解决方案网站seo论坛站长交流
  • 佛山购物网站建设河北网站开发费用
  • 网站建设投放广告seoapp推广
  • 鞍山网站制作开发桂林漓江一号
  • 免费的网站后台管理系统wordpress插件访客
  • 杭州网站建站模板高级网站开发工程师考试题
  • 青岛提供网站建设哪家便宜淘宝官方网站登录页面
  • 广州骏域网站建设专家手机电脑版物流网站
  • 职高网站建设知识点网站设计开发中的具体步骤
  • 苏州专业建站艺术设计类网站
  • 重庆点优建设网站公司网站建设的基本特点
  • 网站ie不兼容做外贸生意在哪个网站
  • 做网站设计的公司名字校园网站开发需求文字
  • 百度贴吧有没有做网站的人做打鱼网站
  • 天津市建设银行网站wordpress 谷歌云