mercredi 9 août 2017

Throw new exception with Java Reflection

I have one class called IntegrationCmd(controller) and it instances a class in runtime with Java Reflection. In the class that I called with Reflection, I need to throw an exception with a specific message. The problem is that when I throw an excepcion the method call the InvocationTargetException and put my message to null. How I resolve this problem?

IntegratedCmd:

String providerClass = Legacy.getProperty(externalId);
Class<?> cProvider = Class.forName(providerClass);
Constructor<?> ctor2 = cProvider.getConstructor();
Object object2 = ctor2.newInstance();
Object header = cProvider.getMethod("loadFile", 
String.class).invoke(object2, fullpathXml);

boolean bool = (Boolean)cProvider.getMethod("validate", Object.class, ProcessBridge.class).invoke(object2, header, bridge);

The Class Instanced in Runtime:

throw new IntegrationException(LoggingUtils.getMessageAndWriteLog(OctoTelematics.class, "validateBody","user", MessagesBusiness.ERROR_NonTelematicApol));

Thanks.





Aucun commentaire:

Enregistrer un commentaire