Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java反射引发新异常_Java_Exception_Reflection - Fatal编程技术网

使用Java反射引发新异常

使用Java反射引发新异常,java,exception,reflection,Java,Exception,Reflection,我有一个名为IntegrationCmd(controller)的类,它在运行时使用Java反射来实例一个类。 在我用反射调用的类中,我需要抛出一个带有特定消息的异常。问题是,当我抛出异常时,该方法调用InvocationTargetException并将我的消息设置为null。 我如何解决这个问题 IntegratedCmd: String providerClass = Legacy.getProperty(externalId); Class<?> cProvider = Cl

我有一个名为IntegrationCmd(controller)的类,它在运行时使用Java反射来实例一个类。 在我用反射调用的类中,我需要抛出一个带有特定消息的异常。问题是,当我抛出异常时,该方法调用InvocationTargetException并将我的消息设置为null。 我如何解决这个问题

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);

谢谢。

你说的“将我的邮件设为空”是什么意思?演示。当我执行抛出新的IntegrationException时,您通常可以使用
getTargetException()
@Andreas提取底层(原始)异常。。。它调用方法public InvocationTargetException(Throwable target){super((Throwable)null);//Disallow initCause this.target=target;},此方法接收null并返回null。@Lau13因此您的
IntegrationException
被包装在
InvocationTargetException
中,调用的反射代码可以通过调用
getCause()
将其展开。我看不出有什么问题。
InvocationTargetException
甚至是一个已检查的异常,试图强迫您处理它,所以请处理它。您所说的“将我的消息设置为null”是什么意思?演示。当我执行抛出新的IntegrationException时,您通常可以使用
getTargetException()
@Andreas提取底层(原始)异常。。。它调用方法public InvocationTargetException(Throwable target){super((Throwable)null);//Disallow initCause this.target=target;},此方法接收null并返回null。@Lau13因此您的
IntegrationException
被包装在
InvocationTargetException
中,调用的反射代码可以通过调用
getCause()
将其展开。我看不出有什么问题。
InvocationTargetException
甚至是一个选中的异常,试图强迫您处理它,所以请处理它。
throw new IntegrationException(LoggingUtils.getMessageAndWriteLog(OctoTelematics.class, "validateBody","user", MessagesBusiness.ERROR_NonTelematicApol));