cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert throws in UDF

Former Member
0 Kudos

Hi experts,

just a maybe simple question:

In a UDF is possible to use throws?

When I use "Create a new function" the first row:

public String example(String valueAsString,Container container){

is not modifiable.

my need is to have this:

public String example(String valueAsString, Container container)

                                          throws IllegalArgumentException, NumberFormatException {

Is possible?

Thanks

Fabio

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Fabio,

When a UDF is created.


public String calculate(String var1, Container container) throws StreamTransformationException{

}

It can only throw StreamTransformationException. We can not add more exception classes.

Why we can not add more exception classes?

As you know, the graphical message mapping will compile into Java class and run on PI Java server. The Java class which is calling the UDF should also handle exceptions thrown by UDF. If PI developer can add all sort of exception classes, how will PI Java class know, which exception it should handle. To avoid it, SAP has restricted (SAP's design), UDF can only through StreamTransformationException.

Answers (2)

Answers (2)

engswee
Active Contributor
0 Kudos

Additionally, if your intention is to raise exception at the message mapping whenever those two exception occurs in your UDF logic, you can just catch those exception, and rethrow them as StreamTransformationException with the associated text.


  try {

   //Do something

  } catch (NumberFormatException e) {

   throw new StreamTransformationException("NumberFormatException Text", e);

  } catch (IllegalArgumentException e) {

   throw new StreamTransformationException("IllegalArgumentException Text", e);

  }

iaki_vila
Active Contributor
0 Kudos

Hi Fabio,

If you want to throw an exception you can follow these blogs:

Regards.