【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);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM