1 /*
2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 /*
27  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
28  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
29  *
30  * The original version of this source code and documentation
31  * is copyrighted and owned by Taligent, Inc., a wholly-owned
32  * subsidiary of IBM. These materials are provided under terms
33  * of a License Agreement between Taligent and Sun. This technology
34  * is protected by multiple US and International patents.
35  *
36  * This notice and attribution to Taligent may not be removed.
37  * Taligent is a registered trademark of Taligent, Inc.
38  *
39  */
40 
41 package java.util;
42 
43 /**
44  * Signals that a resource is missing.
45  * @see java.lang.Exception
46  * @see ResourceBundle
47  * @author      Mark Davis
48  * @since       1.1
49  */
50 public class MissingResourceException extends RuntimeException {
51 
52     /**
53      * Constructs a MissingResourceException with the specified information.
54      * A detail message is a String that describes this particular exception.
55      * @param s the detail message
56      * @param className the name of the resource class
57      * @param key the key for the missing resource.
58      */
MissingResourceException(String s, String className, String key)59     public MissingResourceException(String s, String className, String key) {
60         super(s);
61         this.className = className;
62         this.key = key;
63     }
64 
65     /**
66      * Constructs a {@code MissingResourceException} with
67      * {@code message}, {@code className}, {@code key},
68      * and {@code cause}. This constructor is package private for
69      * use by {@code ResourceBundle.getBundle}.
70      *
71      * @param message
72      *        the detail message
73      * @param className
74      *        the name of the resource class
75      * @param key
76      *        the key for the missing resource.
77      * @param cause
78      *        the cause (which is saved for later retrieval by the
79      *        {@link Throwable.getCause()} method). (A null value is
80      *        permitted, and indicates that the cause is nonexistent
81      *        or unknown.)
82      */
MissingResourceException(String message, String className, String key, Throwable cause)83     MissingResourceException(String message, String className, String key, Throwable cause) {
84         super(message, cause);
85         this.className = className;
86         this.key = key;
87     }
88 
89     /**
90      * Gets parameter passed by constructor.
91      *
92      * @return the name of the resource class
93      */
getClassName()94     public String getClassName() {
95         return className;
96     }
97 
98     /**
99      * Gets parameter passed by constructor.
100      *
101      * @return the key for the missing resource
102      */
getKey()103     public String getKey() {
104         return key;
105     }
106 
107     //============ privates ============
108 
109     // serialization compatibility with JDK1.1
110     @java.io.Serial
111     private static final long serialVersionUID = -4876345176062000401L;
112 
113     /**
114      * The class name of the resource bundle requested by the user.
115      * @serial
116      */
117     private String className;
118 
119     /**
120      * The name of the specific resource requested by the user.
121      * @serial
122      */
123     private String key;
124 }
125