V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
LangInteger
V2EX  ›  问与答

关于 Java 受检异常与非受检异常的争议

  •  
  •   LangInteger · Dec 14, 2019 · 2545 views
    This topic created in 2338 days ago, the information mentioned may be changed or developed.

    近日阅读 Java Language Specification 11,发现文档中提到

    • Most user-defined exceptions should be checked exceptions.

    但是 Stackoverflow 上的这个提问 Understanding checked vs unchecked exceptions in Java 又让我认识到另外两点

    • Use checked exceptions for recoverable conditions and runtime exceptions for programming errors (From Effective Java Item 58 in 2nd edition)
    • 很多高赞回答让我感觉自己基本不应该定义 Checked Exception 的子类

    问题:

    • JSL 在这个问题上的坚持算是孤注一掷还是曲高和寡呢?
    5 replies    2019-12-14 19:26:36 +08:00
    passerbytiny
        1
    passerbytiny  
       Dec 14, 2019
    没有金刚钻,不要设计受检异常,也别阻挠有钻的人设计受检异常。
    lhx2008
        2
    lhx2008  
       Dec 14, 2019 via Android
    这两个有关系吗。。文档只是说用户尽量不要定义运行时异常类
    SoloCompany
        4
    SoloCompany  
       Dec 14, 2019 via iPhone
    ce 只是在玩具项目里面看起来不错,在真正实践中大部分情况下是砸自己的脚以及带来更多质量低下的代码
    LangInteger
        5
    LangInteger  
    OP
       Dec 14, 2019 via Android
    @lhx2008 有关系呀,我滴朋友,我看除了 jls 基本上都推荐 uncheck exception。这里官方的说法和大家的做法有点出入惹。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1156 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:38 · PVG 07:38 · LAX 16:38 · JFK 19:38
    ♥ Do have faith in what you're doing.