cancel
Showing results for 
Search instead for 
Did you mean: 

Simple question on Java - How to process data of 'for loop'

Former Member
0 Kudos

Hi Experts,

My WD code looks like as below:

int i = 0;
String name = "";
int j = 0;
j =wdContext.currentContextElement().getFromUserIDForRoleAssignment();
int k = 0;
k =wdContext.currentContextElement().getToUserIDForRoleAssignment();
int l = 0;
l = j + l;
for (j = l; j <= k; j++) {
String s = String.valueOf(j);

IUser thisUser = myUserFactory.getUserByLogonID(s);

a =thisUser.isMemberOfRole(role1.getUniqueID(), true);
if (a == false) {
role1.addUserMember(thisUser.getUniqueID());
role2.removeUserMember(thisUser.getUniqueID());
gsucc_users = gsucc_users + 1;
}
role1.save();
role1.commit();
role2.save();
role2.commit();
}
} catch (UMException e) {
wdComponentAPI.getMessageManager().reportWarning("user: "+ e.getLocalizedMessage());

Out of 100 records say for 10 records following statement is failing

IUser thisUser = myUserFactory.getUserByLogonID(s);

In such cases I am getting message sent by following code. The code is not getting executed at all for all 90 records.

wdComponentAPI.getMessageManager().reportWarning("user: "+ e.getLocalizedMessage());

How I can avoid the issue. I want the code to get executed for 90 records.

I commented out the following statement. It does not help.

wdComponentAPI.getMessageManager().reportWarning("user: "+ e.getLocalizedMessage());

Please help.

Regards,

Gary

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Gary,

Please disregard the advice of Venkatraman. First you should not catch general Exceptions. Second once you catch exception you should take appropriate actions or not catch that exception at all. Failing to follow the above principals would make impossible to investigate bugs, because the exceptions will disappear without a trace.

The reason you are getting ("user: "+ e.getLocalizedMessage()) executed only for the 10 failing records is most likely because when "IUser thisUser = myUserFactory.getUserByLogonID(s);" fails an UMException is thrown. That exception is being caught by the catch block u201Ccatch (UMException e) {u201C and then the statement inside the catch block is being executed.

When there is no UMException, the catch block is not executed.

You should not rely on the catch block for logging. Instead you should add a statement that prints the information that you need outside of the catch block.

Of course you can not use UMException. getLocalizedMessage() without instance of UMException.

Therefore you will have to find that information from somewhere else like the "IUser thisUser".

Regards,

Ventsi Tsachev

SAP Technology Development Support

Palo Alto, Ca (USA)

Former Member
0 Kudos

Hi,

Surround this line with a try catch block and do nothing in the catch block.


try{
  IUser thisUser = myUserFactory.getUserByLogonID(s);
}
catch(Exception e){
}

Thanks,

Venkat