1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package java.lang; 19 20/** 21 * Thrown when a class loader is unable to find a class. 22 */ 23public class ClassNotFoundException extends ReflectiveOperationException { 24 25 private static final long serialVersionUID = 9176873029745254542L; 26 27 private Throwable ex; 28 29 /** 30 * Constructs a new {@code ClassNotFoundException} that includes the current 31 * stack trace. 32 */ 33 public ClassNotFoundException() { 34 super((Throwable) null); 35 } 36 37 /** 38 * Constructs a new {@code ClassNotFoundException} with the current stack 39 * trace and the specified detail message. 40 * 41 * @param detailMessage 42 * the detail message for this exception. 43 */ 44 public ClassNotFoundException(String detailMessage) { 45 super(detailMessage, null); 46 } 47 48 /** 49 * Constructs a new {@code ClassNotFoundException} with the current stack 50 * trace, the specified detail message and the exception that occurred when 51 * loading the class. 52 * 53 * @param detailMessage 54 * the detail message for this exception. 55 * @param exception 56 * the exception which occurred while loading the class. 57 */ 58 public ClassNotFoundException(String detailMessage, Throwable exception) { 59 super(detailMessage); 60 ex = exception; 61 } 62 63 /** 64 * Returns the exception which occurred when loading the class. 65 * 66 * @return Throwable the exception which occurred while loading the class. 67 */ 68 public Throwable getException() { 69 return ex; 70 } 71 72 /** 73 * Returns the cause of this Throwable, or {@code null} if there is no 74 * cause. 75 * 76 * @return Throwable the receiver's cause. 77 */ 78 @Override 79 public Throwable getCause() { 80 return ex; 81 } 82} 83