Products | Versions |
---|---|
TIBCO BusinessEvents Enterprise Edition | - |
Not Applicable | - |
Resolution:
Description:
===========
Throwing Exception from custom Java function in TIBCO BusinessEvents .
Environment:
===========
All Operating Systems
TIBCO BusinessEvents 4.x,5.x
Resolution:
===========
TIBCO BusinessEvents supports throwing only RuntimeException from custom Java code . Note that any other exception thrown from custom Java code has to be wrapped as an instance of Runtime Exception.
Custom Function Code :
public static void exceptionThrow() throws RuntimeException
{
try
{
int a = 7 / 0; // This line will throw arithmetic exception
System.out.println("Quotient" + String.valueOf(a));
}
catch (Exception exception)
{
if (exception instanceof RuntimeException)
{
throw new RuntimeException(); //Throws runtime exception
}
else
{
//Wrap any other exception into an instance of runtime exception before throwing
throw new RuntimeException("Not a runtime Exception", exception);
}
}
}
Catalog Function for the exceptionThrow method :
<function>
<name>ReturnThrow</name>
<method>exceptionThrow</method>
<class>com.test.ObjectReturn</class>
<async>false</async>
<reevaluate>true</reevaluate>
<isActionOnly>true</isActionOnly>
<tooltip>
<synopsis>Returns nothing</synopsis>
<returns type='void'></returns>
</tooltip>
</function>
TIBCO BusinessEvents sample code to catch exception thrown from custom code :
try
{
Testing.ReturnThrow();
}
catch (Exception e)
{
System.debugOut("In catch");
}