1f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 2f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project 3f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 4f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * you may not use this file except in compliance with the License. 6f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * You may obtain a copy of the License at 7f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 8f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 10f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * See the License for the specific language governing permissions and 14f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * limitations under the License. 15f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 16f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 17f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/** 18f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Exceptions across method calls 19f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 20f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectpublic class Main { 21f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project public static void main (String args[]) { 22f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project try { 23f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project catchAndRethrow(); 24f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } catch (NullPointerException npe) { 25f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project System.out.print("Got an NPE: "); 26f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project System.out.println(npe.getMessage()); 27f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project npe.printStackTrace(); 28f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } 29f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } 30f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 31f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project private static void catchAndRethrow() { 32f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project try { 33f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project throwNullPointerException(); 34f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } catch (NullPointerException npe) { 35f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project NullPointerException npe2; 36f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project npe2 = new NullPointerException("second throw"); 37f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project npe2.initCause(npe); 38f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project throw npe2; 39f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } 40f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } 41f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 42f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project private static void throwNullPointerException() { 43f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project throw new NullPointerException("first throw"); 44f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } 45f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 46