Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
hanoijolly
Contributor
Contributor

catching exceptions from a routine in tMap without rejecting the row

Hi, 
My use case is quite simple, I use a tFileInputXML ------> tMap -------->tFileOutputXML
In the tMap, I want to use a routine do multiple specific checks on multiple dates columns from the input but : 
- if the check fails, I would like to : 
      1) throw an exception to be caught and logged in a log file (I use a tAssert----->tFlowToIterate ---->tRunJob ) to write specific logging format to do this
      2) return an empty date to be written in the XML output
- if the check is a success, I transform the date format to another pattern and send it to the output

My problem is that the throwing of an Exception (in my routine) seems to "kill" the whole row and does not allow me to return "" at the end... I do not succeed to throw an exception without rejecting the whole row.
Could you please help me with this ? 

I have tried below example code in a routine.
package routines;
import routines.system.LogCatcherUtils;
import routines.system.ResumeUtil;
public class field_too_long {

/**
* helloExample: not return value, only print "hello" + message.
*
*
* {talendTypes} String
*
* {Category} User Defined
*
* {param} string("world") input: The string need to be printed.
* {param} LogCatcherUtils(tLogCatcher_1) input
* {param} Map(globalMap) input
* {param} ResumeUtil(resumeUtil) input
*
* {example} helloExemple("world") # hello world !.
*/
public static String String_too_long(String field, LogCatcherUtils tLogCatcher_1,final java.util.Map<String, Object> globalMap,ResumeUtil resumeUtil) {
String new_field = field;
String tmp = "";
tmp = field.replaceAll(" +", " ");
new_field = tmp.replaceAll("\t+", "\t");
if(new_field.length()>3){ //You can change it to 4000.
resumeUtil.addLog("USER_DEF_LOG", "NODE:tWarn_1", "", Thread
.currentThread().getId()
+ "", "WARN", "", "this is a warning", "", "");
tLogCatcher_1.addMessage("tWarn", "tWarn_1", 4,
"this is a warning", 42);
}
return new_field;
}
}

but I did not succeed to have those example work...
When not using tLogCatcher_1Process(globalMap) in the routine, it seems the log is not pushed to the tLogCatcher. But when I try to add it to the routine, I get a compilation error : 
The method tLogCatcher_1Process(Map<String,Object>) is undefined for the type MyClass

Best regards. 

Labels (2)
5 Replies
Anonymous
Not applicable

Hi  hanoijolly,
Could you please post your current job setting screenshots into forum? Which will be helpful for us to address your issue.
Best regards
Sabrina
hanoijolly
Contributor
Contributor
Author

Hi, 
Sorry, I thought the short description was clearer. 
Here are the pictures. 
I need a routine to do the date checking because I need it to be re-used on a lot of columns. 
For now, in the picture, the routine is only called once in the "Var" area of the tMap on a single date... If I succeed, then I will call it on each date. 
When there is an error IN THE ROUTINE, I would like to log the error in a log file but return a ""
Best regards.  
  0683p000009MFqy.jpg
0683p000009MGGG.jpg
0683p000009MGGL.jpg
hanoijolly
Contributor
Contributor
Author

xdshi wrote:
Hi  hanoijolly,
Could you please post your current job setting screenshots into forum? Which will be helpful for us to address your issue.
Best regards
Sabrina

Hi xdshi, 
I sent the screenshots, do any of you have an idea about how I could have the routine throw something in my log without rejecting the row ? 
I thank you in advance for your help. 

Best regards. 
Anonymous
Not applicable

Hi,
Sorry for dealy!
From you screenshots, we don't see that you have set "catch output rejected" option as true. Could you please take a look at it?
Best regards
Sabrina
0683p000009MGFT.png
hanoijolly
Contributor
Contributor
Author

Hi Sabrina,
Thank you for your feedback. If I am not missing anything, setting up "catch output rejected" will make all the "rejected" lines go to the output I configured for this. 
What I am trying to achieve is that ALL rows go to the same output (if the routine is a success or if it fails). But, if my routine (which is used to create a variable) fails to process, I want it to send an exception to be caught by a logger, AND the routine returns "" so that the row can be processed. 
Actually, I have all the rows, the routine returns a "" when not working, BUT the sending of the exception is never logged and I cannot figure out why...