One Star

((String)globalMap.get("tSendMail_1_ERROR_MESSAGE"))

Hi
Im trying to get the error message populated here when tSendMail component throws an exception.
javax.mail.MessagingException: Could not connect to SMTP host:
I dont see it doing it in the component, i.e.
} catch(Exception e){
<%if (isDieOnError){%>
throw(e);
<%}else{%>
System.err.println(e.toString());
<%}%>
}
Is it possible for me to add custom code to get it to populate the tSendMail_1_ERROR_MESSAGE property?
If so, please advise
thank you

5 REPLIES
Community Manager

Re: ((String)globalMap.get("tSendMail_1_ERROR_MESSAGE"))

Hi
Make sure the 'die on error' option is checked on the tSendMail component, so that the exception will be thrown. Normally, we use tLogCatcher component to capture the Java exception. In this case, you don't need to hard code to capture the exception message, the exception message is put into the global variable ((String)globalMap.get("tSendMail_1_ERROR_MESSAGE")), and you can use this global variable to get the exception message if tSendMail fails, for example:
tSendMail_1
|
onsubjoberror
|
tJava
on tJava:
String errorMessage = ((String)globalMap.get("tSendMail_1_ERROR_MESSAGE"));
System.out.println(errorMessage);
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: ((String)globalMap.get("tSendMail_1_ERROR_MESSAGE"))

Thanks for replying.
The sendmail component is inside a joblet utilising the flow.
I dont want the main job to die (which happens when I select 'die on error' on the joblet sendmail component) but to continue processing the next record.
Could I programmatically set the ERROR message property based on the individual record failure?
Its currently printing the failure and moving onto the next record.
Community Manager

Re: ((String)globalMap.get("tSendMail_1_ERROR_MESSAGE"))

Hi
Yes, the job will die and stop to run if this option 'die on error' is checked and the job has an error in the current record. According to your request, you need to redesign the job, use tRunJob to call a child job instead of using joblet. The job design looks like:
parent job:
tFileInputDelimited--row1--tFlowToIterate--iterate-->tRunJob
on tRunJob: call the child job, uncheck the option 'die on error' so as to continue to execute next record even though an exception is thrown in the child job.
child job:
tSendMail
tLogCatcher-main--tLogRow
on tSendMail: check the option 'die on error'.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: ((String)globalMap.get("tSendMail_1_ERROR_MESSAGE"))

Thanks Shong.
Based on my request, "error message populated here when tSendMail component throws an exception"
Its currently printing the exception to the console based on:
<%}else{%>
System.err.println(e.toString());
<%}%>
}
I havent selected 'Die on error' for the sendmail component so its printing to the console as above.
Can I instead have it populate the ERROR_MESSAGE property.. or is that only accessible and populated from a DIE ?
Community Manager

Re: ((String)globalMap.get("tSendMail_1_ERROR_MESSAGE"))

Hi
If the option 'die on error' is not checked, the exception is not thrown out and printed to the console. You need to modify the component and hard code to populate the ERROR_MESSAGE property and put the error message to a global variable. This is not recommended, because you have to migrate the component also when upgrading product in the future. I still suggest you to redesign the job as I did.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business