zoukankan      html  css  js  c++  java
  • java throw和throws使用分析

    代码实例:

     问题:为什么testRunntimeException()方法没有出现编译错误提示,而testCheckedException()方法却出现unhandle exception?

    分析:

      Excepiton分两类:checked exception、runtime exception;直接继承自Exception就是checked exception,继承自RuntimeException就是runtime的exception。

      你可以简单地理解checked exception就是要强制你去处理这个异常(不管你throws多少层,你终归要在某个地方catch它);而runtime exception则没有这个限制,你可以自由选择是否catch。

      那些强制异常处理的代码块,必须进行异常处理,否则编译器会提示“Unhandled exception type Exception”错误警告。

    这里testRunntimeException()方法是runtime exception异常,testCheckedException()方法是 exception异常,属于checked exception异常

    所以testCheckedException()方法却出现unhandle exception

    怎么解决testCheckedException()方法却出现unhandle exception?

  • 相关阅读:
    子序列自动机
    poj 暴力水题
    小白贪心题
    组合数+费马大/小定理
    随机数法
    vector的二维用法+前缀和
    巨思维题
    思维水题
    Codeforces Round #323 (Div. 2) D.Once Again... (nlogn LIS)
    Codeforces Round #325 (Div. 2) D. Phillip and Trains (BFS)
  • 原文地址:https://www.cnblogs.com/myseries/p/12895090.html
Copyright © 2011-2022 走看看