java 板


LINE

出个懒人包… 因为讨论的是 Java 的物,所以 "人" 的部分就不重要了 1. 问: 为什麽 Thread.Sleep() 要用 try-catch 来坦? 2. 某人开大绝放 LMGTFY 出来咬人; 点出这个 link http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html 3. 有人佛心来着 po 了一段把 Thread.Sleep() 用 try-catch 坦起来且一劳永逸的办法 4. 某人出来碎碎念;主张 InterruptedException 背後的案情并不单纯 http://www.ibm.com/developerworks/java/library/j-jtp05236.html 5. 某人继续碎碎念;主张所有 checked exception 背後的案情都不单纯,难以一言尽之 http://tinyurl.com/yewgxls 6. 有人提出一个很有趣的说法;主张一言得以尽之;此一言为: sleep 被意外中断很容易修复,所以被包在 checked exception 7. 某人请有人对 "很容易修复 --所以--> 被包在 checked exception" 这背後的逻辑关系再作解释 反过来说,也就是讨论开始走向 checked exception 与 unchecked exception 的界限在哪里? 8. 某人与有人就跑去以信件讨论到底何谓 "很容易修复" "修复" 的定义为何? "容易" 的定义又为何? 9. 最後,某人把 http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html 再仔细看了一次,才发现,其实 Java 规格书很简单的就把事情讲清楚了; (易言之,某人之前的碎碎念像是在重新发明轮子一样…) 11.2 Compile-Time Checking of Exceptions A compiler for the Java programming language checks, at compile time, that a program contains handlers for checked exceptions, by analyzing which checked exceptions can result from execution of a method or constructor. For each checked exception which is a possible result, the throws clause for the method (§8.4.6) or constructor (§8.8.5) must mention the class of that exception or one of the superclasses of the class of that exception. This compile-time checking for the presence of exception handlers is designed to reduce the number of exceptions which are not properly handled. 11.2.5 Why Runtime Exceptions are Not Checked The runtime exception classes (RuntimeException and its subclasses) are exempted from compile-time checking because, in the judgment of the designers of the Java programming language, having to declare such exceptions would not aid significantly in establishing the correctness of programs. Many of the operations and constructs of the Java programming language can result in runtime exceptions. The information available to a compiler, and the level of analysis the compiler performs, are usually not sufficient to establish that such run-time exceptions cannot occur, even though this may be obvious to the programmer. Requiring such exception classes to be declared would simply be an irritation to programmers. For example, certain code might implement a circular data structure that, by construction, can never involve null references; the programmer can then be certain that a NullPointerException cannot occur, but it would be difficult for a compiler to prove it. The theorem-proving technology that is needed to establish such global properties of data structures is beyond the scope of this specification. 也就是说 1. 之所以在 compile time 来 check 某些 exception 是否有被处理 是为了减少在程式里没有被处理的 exception 的数量 --> 这就是所谓 checked exception 2. 之所以另一些 exception 没有在 compile time 被 check 是因为 1. 对 compiler 来说,这一类 exception 太难 check 了 (注1) 让 programmer 自己去避免吧 2. 在 Java 设计者的主观认定里 就算强制在 compile time 来 check 这类 exception 对程式的正确度也没什麽帮助 --> 此为 unchecked exception 或 runtime exception Java 规格书万岁!! 注1: static analysis 一直在进步 Java 上早已经有各式各样研究的实作, C# 就比较少,只有 Microsoft Research 自己在搞 但在 .Net 4.0 里 contract-based programming 将昇为第一等公民, 且加入了对应的 static analysis 的工具 .Net 4.0 Beta2 快出来了,有兴趣可以尝试看看 C# 与 static analysis --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 65.87.177.87
1F:推 PsMonkey:居然能等得到懒人包... Java 版救星阿... (y) 10/08 11:03
2F:推 H45:阿...私下信件还在进行中耶 XD 10/08 11:20
3F:推 kene:那我们可以等待懒人包 SP1 吗? XD 10/08 12:06
这几天打的中文的量让我已经没力了… XD 要请 H45 接手了
4F:推 PsMonkey:私通是不道德的 [怒指] 10/08 15:21
我也是不得已啊;这个版空白的地方太小,以致於我无法写下所有的论证… XD
5F:推 qrtt1:effective java 有章专讲 exception :) 10/08 23:00
一直没机会好好把这本书看完,後来就跑去搞C#了 XD ※ 编辑: AmosYang 来自: 65.87.177.87 (10/09 08:18)







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP