Home | History | Annotate | Download | only in multidexlegacyandexception
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.multidexlegacyandexception;
     18 
     19 public class ClassInSecondaryDex {
     20     private boolean condition;
     21 
     22     public ClassInSecondaryDex(boolean condition) {
     23         this.condition = condition;
     24     }
     25 
     26     public void canThrow1() throws ExceptionInMainDex, ExceptionInMainDex2,
     27             ExceptionInSecondaryDexWithSuperInMain {
     28         if (condition) {
     29             throw new ExceptionInMainDex();
     30         }
     31     }
     32 
     33     public void canThrow2() throws ExceptionInSecondaryDex, ExceptionInSecondaryDex2,
     34             ExceptionInSecondaryDexWithSuperInMain {
     35         if (condition) {
     36             throw new ExceptionInSecondaryDex();
     37         }
     38     }
     39 
     40     public static void canThrowAll(Throwable toThrow) throws Throwable {
     41         if (toThrow != null) {
     42             throw toThrow;
     43         }
     44     }
     45 
     46     public int get1() {
     47         try {
     48             canThrow1();
     49             canThrow2();
     50             return 1;
     51         } catch (ExceptionInMainDex e) {
     52             return 10;
     53         } catch (ExceptionInSecondaryDex e) {
     54             return 11;
     55         } catch (OutOfMemoryError e) {
     56             return 12;
     57         } catch (CaughtOnlyException e) {
     58             return 17;
     59         } catch (SuperExceptionInSecondaryDex|SuperExceptionInMainDex e) {
     60             return 23;
     61        }
     62     }
     63 
     64     public int get2() {
     65         try {
     66             canThrow2();
     67             canThrow1();
     68             return 1;
     69         } catch (ExceptionInMainDex e) {
     70             return 10;
     71         } catch (ExceptionInSecondaryDex e) {
     72             return 11;
     73         } catch (OutOfMemoryError e) {
     74             return 12;
     75         } catch (CaughtOnlyException e) {
     76             return 17;
     77         } catch (SuperExceptionInSecondaryDex e) {
     78             return 23;
     79         } catch (SuperExceptionInMainDex e) {
     80             return 27;
     81        }
     82     }
     83 
     84 }
     85