|
1 | 1 | package com.javadiscord.jdi.core.interaction;
|
2 | 2 |
|
| 3 | +import java.lang.reflect.InvocationTargetException; |
3 | 4 | import java.lang.reflect.Method;
|
4 | 5 | import java.lang.reflect.Parameter;
|
5 | 6 | import java.util.*;
|
|
12 | 13 | import com.javadiscord.jdi.internal.ReflectiveLoader;
|
13 | 14 | import com.javadiscord.jdi.internal.ReflectiveSlashCommandClassMethod;
|
14 | 15 | import com.javadiscord.jdi.internal.ReflectiveSlashCommandLoader;
|
15 |
| -import com.javadiscord.jdi.internal.exceptions.InstantiationException; |
16 | 16 |
|
17 | 17 | import org.apache.logging.log4j.LogManager;
|
18 | 18 | import org.apache.logging.log4j.Logger;
|
@@ -89,14 +89,21 @@ private void invokeHandler(
|
89 | 89 | Class<?> handler,
|
90 | 90 | Method method,
|
91 | 91 | List<Object> paramOrder
|
92 |
| - ) throws Exception { |
93 |
| - if (cachedInstances.containsKey(handler.getName())) { |
94 |
| - method.invoke(cachedInstances.get(handler.getName()), paramOrder.toArray()); |
95 |
| - } else { |
96 |
| - Object handlerInstance = handler.getDeclaredConstructor().newInstance(); |
97 |
| - cachedInstances.put(handler.getName(), handlerInstance); |
98 |
| - injectComponents(handlerInstance); |
99 |
| - method.invoke(handlerInstance, paramOrder.toArray()); |
| 92 | + ) throws InstantiationException { |
| 93 | + try { |
| 94 | + if (cachedInstances.containsKey(handler.getName())) { |
| 95 | + method.invoke(cachedInstances.get(handler.getName()), paramOrder.toArray()); |
| 96 | + } else { |
| 97 | + Object handlerInstance = handler.getDeclaredConstructor().newInstance(); |
| 98 | + cachedInstances.put(handler.getName(), handlerInstance); |
| 99 | + injectComponents(handlerInstance); |
| 100 | + method.invoke(handlerInstance, paramOrder.toArray()); |
| 101 | + } |
| 102 | + } catch ( |
| 103 | + InvocationTargetException | IllegalAccessException | NoSuchMethodException |
| 104 | + | InstantiationException e |
| 105 | + ) { |
| 106 | + throw new InstantiationException(e.getLocalizedMessage()); |
100 | 107 | }
|
101 | 108 | }
|
102 | 109 |
|
|
0 commit comments