172b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe/* 272b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * Copyright (C) 2014 The Android Open Source Project 372b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * 472b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License"); 572b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * you may not use this file except in compliance with the License. 672b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * You may obtain a copy of the License at 772b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * 872b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * http://www.apache.org/licenses/LICENSE-2.0 972b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * 1072b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * Unless required by applicable law or agreed to in writing, software 1172b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS, 1272b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1372b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * See the License for the specific language governing permissions and 1472b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe * limitations under the License. 1572b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe */ 1672b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe 1772b3e430d880ef57eaa6a34a0822165994052202Andreas Gampepublic class Main { 1872b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe static public void main(String[] args) throws Exception { 1972b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe try { 2072b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe check(false); 2172b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } catch (Throwable t) { // Should catch the NoClassDefFoundError 2272b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe System.out.println("Caught " + t.getClass()); 2372b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } 2472b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } 2572b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe 2672b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe private static void check(boolean b) { 2772b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe try { 2872b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe if (b) { // Need this to not be dead code, but also not be invoked. 2972b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe throwsTestException(); // TestException is checked, so we need something potentially 3072b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe // throwing it. 3172b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } 3272b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe throw new RuntimeException(); // Trigger exception handling. 3372b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } catch (TestException e) { // This handler will have an unresolvable class. 3472b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } catch (Exception e) { // General-purpose handler 35822266b9dc7d8dc9e084192ae0f4bc95af4e8cf8Ian Rogers System.out.println("Got expected exception."); 3672b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } 3772b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe } 3872b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe 3972b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe // This avoids having to construct one explicitly, which won't work. 4072b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe private static native void throwsTestException() throws TestException; 4172b3e430d880ef57eaa6a34a0822165994052202Andreas Gampe} 42