September 2019
Intermediate to advanced
816 pages
18h 47m
English
For inspecting the annotations of the thrown exceptions, we need to call the getAnnotatedExceptionTypes() method:

This method returns the thrown exceptions types included those that are annotated:
Class<Melon> clazz = Melon.class;Method methodEat = clazz.getDeclaredMethod("eat");AnnotatedType[] exceptionsTypes = methodEat.getAnnotatedExceptionTypes();
The returned array printed via Arrays.toString() reveals a single result:
[@modern.challenge.Runtime() java.lang.IllegalStateException]
Extracting the first exception type can be accomplished as follows:
// class java.lang.IllegalStateException ...