Constructor getGenericExceptionTypes() method in Java with Examples Last Updated : 29 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The getGenericExceptionTypes() method of java.lang.reflect.Constructor class is used to return the exception types present on this constructor object as an array. The returned array of objects represent the exceptions declared to be thrown by this constructor object. If this constructor declares no exceptions in its throws clause then this method returns an array of length 0. Syntax: public Type[] getGenericExceptionTypes() Parameters: This method accepts nothing. Return: This method returns an array of Types that represent the exception types thrown by the underlying executable. Exception: This method throws following exceptions: GenericSignatureFormatError: if the generic method signature does not conform to the format specified in The Java™ Virtual Machine Specification. TypeNotPresentException: if the underlying executable's throws clause refers to a non-existent type declaration. MalformedParameterizedTypeException: if the underlying executable's throws clause refers to a parameterized type that cannot be instantiated for any reason. Below programs illustrate getGenericExceptionTypes() method: Program 1: Java // Java program to illustrate // getGenericExceptionTypes() method import java.io.IOException; import java.lang.reflect.*; public class GFG { public static void main(String[] args) { // create a class object Class classObj = shape.class; // get Constructor object // array from class object Constructor[] cons = classObj.getConstructors(); // get array of GenericExceptionTypes Type[] exceptions = cons[0].getGenericExceptionTypes(); // print length of GenericExceptionTypes array System.out.println("GenericExceptions : "); for (int i = 0; i < exceptions.length; i++) System.out.println(exceptions[i]); } // demo class public class shape { public shape() throws IOException, ArithmeticException, ClassCastException { } } } Output: GenericExceptions : class java.io.IOException class java.lang.ArithmeticException class java.lang.ClassCastException Program 2: Java // Java program to illustrate // getGenericExceptionTypes() method import java.lang.reflect.Constructor; import java.lang.reflect.Type; public class GFG { public static void main(String[] args) { // create a class object Class classObj = String.class; // get Constructor object // array from class object Constructor[] cons = classObj.getConstructors(); // get array of GenericExceptionTypes Type[] exceptions = cons[0].getGenericExceptionTypes(); // print length of GenericExceptionTypes array System.out.println( "No of Generic Exception thrown : " + exceptions.length); } } Output: No of Generic Exception thrown : 0 References: https://docs.oracle.com/javase/10/docs/api/java/lang/reflect/Constructor.html#getGenericExceptionTypes() Comment More infoAdvertise with us Next Article Constructor getGenericExceptionTypes() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Constructors Java-Functions java-lang-reflect-package Practice Tags : Java Similar Reads Constructor getGenericParameterTypes() method in Java with Examples The getGenericParameterTypes() method of java.lang.reflect.Constructor class is used to return an array of objects that represent the types of the parameters present on this constructor object. The arrangement Order of the returned array from this method is the same as the order of parameter present 2 min read Constructor getAnnotatedReceiverType() method in Java with Examples The getAnnotatedReceiverType() method of a Constructor class is used to return an AnnotatedType object that represents the AnnotatedType to specify the receiver type of this constructor. If the constructor has a receiver parameter then The receiver type of a constructor is available. If this constru 2 min read Constructor getAnnotatedReturnType() method in Java with Examples The getAnnotatedReturnType() method of a Constructor class is used to return an AnnotatedType object which represents AnnotatedType to specify return type of Constructor Object. The returned AnnotatedType represents implementation of AnnotatedType itself or any of its sub-interfaces like AnnotatedAr 2 min read Constructor getTypeParameters() method in Java with Examples The getTypeParameters() method of a Constructor class is used to get an array of TypeVariable objects declared by this Constructor Object, in declaration order. Elements of array represent the type variables objects declared by Method. An array of length 0 is returned by this getTypeParameters(), if 2 min read Constructor getDeclaringClass() method in Java with Examples The constructor class provides information about a single constructor for a class and it also provides access to that constructor. The getDeclaringClass() method of java.lang.reflect.Constructor is used to return the class object representing the class that declares the constructor represented by th 2 min read Like