cancel
Showing results for 
Search instead for 
Did you mean: 

Simple UDF question.

Former Member
0 Kudos

hello experts,

Iam very new to java,

iam trying a simple user defined function where I want to throw an exception incase my employee id is blank,such that it should show my exception text("emp id is blank") in my moni transaction if i pass a blank value.

Can this be done without creating a package by some small code in udf's?.

I refered to this blog,(/people/alessandro.guarneri/blog/2006/01/26/throwing-smart-exceptions-in-xi-graphical-mapping)

but this way suggests to create a custom exception in a package etc.. are there any standard exceptions i can throw?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, You can also refer to the blog by Michael, it mentioned a throw generic mapping excepton in any type of mapping:

XI/PI: Throwing Generic Exceptions from any type of Mapping

Regards

Liang

Former Member
0 Kudos

Hi Liang,

I saw the thread you posted.. it is that of a Number gformat ecxeption, i tried the same with the null value exception but its not workign, its giving me some syntax error problem

below is my code,,

any thoughts from you or anyone about it?

//write your code here

if (a.length == 0);

throw new NullValueException('Value is Null);

else

result.addValue(a[0]);

its returning me syntax error saying else statement syntax and nullvalue syntax..

please help me.

thanks.

Former Member
0 Kudos

Hey

>>if (a.length == 0);

You don't need a ; after the end of If statement,please remove that and test your mapping again

It should be like

if (a.length == 0)

Thanx

Aamir

Former Member
0 Kudos

Hey Amir,

thanks for the check..

this is my new code and it keeps giving me the error that a ")" is expected.

//write your code here

if (a.length == 0)

throw new NullValueException (Value is Null) ;

else

result.addValue(a[0]);

I also tried to put mycomment value is null into "".

any corretcions i need to do on this one to make it work?

thanks.

Former Member
0 Kudos

Hey

Could you please post the first line of your code as well.

it will be something like

public void <functionName> ........

I m not sure why you are using an advanced UDF just to throw exception.

Thanx

Aamir

Former Member
0 Kudos

hello Aamir..

here it is..

public void Null1(String[] a,ResultList result,Container container){

Former Member
0 Kudos

Hi,

do this correction:

//write your code here

if (a.length == 0)

throw new NullValueException ("Value is Null") ;

else

result.addValue(a[0]);

--Sankar Choudhury

Former Member
0 Kudos

Hi,

Please use the below code in your UDF:

if (a.length == 0)

throw new RuntimeException('Value is Null);

else

result.addValue(a[0]);

After using the above code, if you get any error, do let me know.

Regards,

Rajeev Gupta

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi All,

I wanted the exception to be thrown based upon if the 'value' exists..the exists checks if the node exists or not..

Also the previous 2 solutions did not work.

this pone works well. it check if the value exists or not and then throws an exception.I also wanted my own string in this exception so i did not try it with the standard functions.

Working code:

String ret = "";

int c = a.length();

if (c == 0)

{

throw new RuntimeException(b);

}

else

{

ret = a;

}

return ret;

Thanks for your help anyway..!!

Edited by: XI_User XI on May 9, 2008 10:24 PM

Former Member
0 Kudos

Hi,

if (a.length == 0);

As I can see, the code has not done that you really want.

It means you just check the queue length is 0 or not, in other words, you check if the incoming message has the tag or not.

standard function "exist" does the exact work.

Based on your requirment, you would like to check if the ID field is blank or not, this means you always have the tag passed in your incoming xml file, you just want to check if there is blank payload or not, this way, you can go ahead just use standard function as ujjwal kumar mentioned.

Regards.

Liang

former_member187563
Contributor
0 Kudos

hi,

As you are new to java,you could have done it without using udf.

You can use a simple if else standard function,and get away with it.

The use of udf has to be done when standard functions are not able to fix the issue.

reward point if helpful

regards,

ujjwal kumar