【Android开发坑系列】之try-catch

        try {
            mViewPager.postDelayed(new Runnable() {                
                @Override
                public void run() {
                    getCurrentPage().render(false);                    
                }
            }, 500);            
        } catch (Exception e) {
            // 可忽略的异常
            LogUtil.i(TAG, "=====");
        }

上面的写法实际上catch不到getCurrentPage().render(false)的异常,postDelayed会造成getCurrentPage().render(false)执行延迟

而需要这样写。

        mViewPager.postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    getCurrentPage().render(false);
                } catch (Exception e) {
                    // 可忽略的异常
                    LogUtil.i(TAG, "======");
                }
            }
        }, 500);

  

原文地址:https://www.cnblogs.com/kaima/p/3179703.html