zoukankan      html  css  js  c++  java
  • Java异常处理

    首次写这个笔记希望对大家有所帮助,有问题大家评论提建议相互讨论学习----大家的建议是我的学习的动力加油------不要喷就好谢谢!

    Java异常处理是先捕获异常try后处理异常catch,需要处理多个异常时则用一个try----多个catch----特殊情况父类catch则一定要写在最后面内容参考如下:

    package YC;
    public class yichang {

        public static void main(String[] args) {
            int[] array= new int[5];
            try {
                System.out.println(array[3]);
                String s = null;
                System.out.println(s.length());
                System.out.println(2/0);
            }  catch (NullPointerException e) {//空类型
                System.out.println("此处出现空指针了");
            }catch (ArrayIndexOutOfBoundsException e) {//用于数组类型
                System.out.println("数组超出使用范围了");
            }catch (Exception e) {//其他类型属于对等类型顺序可以颠倒----但父类(Exception)一定放到最后面类似于default写在最后面
                System.out.println("出现异常了");
            }
        }
        
    }

  • 相关阅读:
    RecyclerView的万能适配器+定义可以到底部自动刷新的RecyclerView
    Material Design 摘要
    模版方法模式
    工厂方法模式
    单例模式
    Android中使用Intent和IntentFilter进行通信
    Json/XML/HTML数据解析
    Java中集合总结
    重构笔记
    Android中ActionBar的使用
  • 原文地址:https://www.cnblogs.com/zw321/p/11299190.html
Copyright © 2011-2022 走看看