< prev index next >

src/java.base/share/classes/java/lang/TypeNotPresentException.java

Print this page




  27 
  28 /**
  29  * Thrown when an application tries to access a type using a string
  30  * representing the type's name, but no definition for the type with
  31  * the specified name can be found.   This exception differs from
  32  * {@link ClassNotFoundException} in that {@code ClassNotFoundException} is a
  33  * checked exception, whereas this exception is unchecked.
  34  *
  35  * <p>Note that this exception may be used when undefined type variables
  36  * are accessed as well as when types (e.g., classes, interfaces or
  37  * annotation types) are loaded.
  38  * In particular, this exception can be thrown by the {@linkplain
  39  * java.lang.reflect.AnnotatedElement API used to read annotations
  40  * reflectively}.
  41  *
  42  * @author  Josh Bloch
  43  * @see     java.lang.reflect.AnnotatedElement
  44  * @since 1.5
  45  */
  46 public class TypeNotPresentException extends RuntimeException {

  47     private static final long serialVersionUID = -5101214195716534496L;
  48 
  49     private String typeName;
  50 
  51     /**
  52      * Constructs a {@code TypeNotPresentException} for the named type
  53      * with the specified cause.
  54      *
  55      * @param typeName the fully qualified name of the unavailable type
  56      * @param cause the exception that was thrown when the system attempted to
  57      *    load the named type, or {@code null} if unavailable or inapplicable
  58      */
  59     public TypeNotPresentException(String typeName, Throwable cause) {
  60         super("Type " + typeName + " not present", cause);
  61         this.typeName = typeName;
  62     }
  63 
  64     /**
  65      * Returns the fully qualified name of the unavailable type.
  66      *


  27 
  28 /**
  29  * Thrown when an application tries to access a type using a string
  30  * representing the type's name, but no definition for the type with
  31  * the specified name can be found.   This exception differs from
  32  * {@link ClassNotFoundException} in that {@code ClassNotFoundException} is a
  33  * checked exception, whereas this exception is unchecked.
  34  *
  35  * <p>Note that this exception may be used when undefined type variables
  36  * are accessed as well as when types (e.g., classes, interfaces or
  37  * annotation types) are loaded.
  38  * In particular, this exception can be thrown by the {@linkplain
  39  * java.lang.reflect.AnnotatedElement API used to read annotations
  40  * reflectively}.
  41  *
  42  * @author  Josh Bloch
  43  * @see     java.lang.reflect.AnnotatedElement
  44  * @since 1.5
  45  */
  46 public class TypeNotPresentException extends RuntimeException {
  47     @java.io.Serial
  48     private static final long serialVersionUID = -5101214195716534496L;
  49 
  50     private String typeName;
  51 
  52     /**
  53      * Constructs a {@code TypeNotPresentException} for the named type
  54      * with the specified cause.
  55      *
  56      * @param typeName the fully qualified name of the unavailable type
  57      * @param cause the exception that was thrown when the system attempted to
  58      *    load the named type, or {@code null} if unavailable or inapplicable
  59      */
  60     public TypeNotPresentException(String typeName, Throwable cause) {
  61         super("Type " + typeName + " not present", cause);
  62         this.typeName = typeName;
  63     }
  64 
  65     /**
  66      * Returns the fully qualified name of the unavailable type.
  67      *
< prev index next >