异常

Posted by Solace Blog on March 20, 2019

异常

异常顶层类Throwable

代码示例

下面两个方法

  • checkedMethod:抛出Exception必须进行处理
  • unCheckedMethod:抛出RuntimeException可以不用处理
public class TestException {
   public static void checkedMethod() throws Exception {
      throw new Exception("checked exception");
   }

   public static void unCheckedMethod() {
      throw new RuntimeException("unChecked exception");
   }

   public static void main(String[] args) {
      TestException.checkedMethod(); // Unhandled exception: java.lang.Exception

      TestException.unCheckedMethod();
   }
}