One Star

Handling with custom messages.

Hello everybody
i am creating a routine which can be used for any job and in that routine adding some JDBC code to connect to the data base and handling the exceptions using try and catch blocks in routine.
the problem i am facing :
================
whenever some error occurred in routine, at that point i can be able to print the custom messages but talend is not stopping the execution. Its continuing the flow of execution.
i wanted to stop the flow of execution whenever i got error in routine and if the job stops execution all the custom messages has to be recorded in to log-file.
Scenario :
=======
tJava---->tOracleConnection------>tOracleInput------>tMap---->tOracleOutput----tOracleCommit.
here i am calling the routine methods through the tJava component and i am handling the SQLException using try catch blocks in routine. it will be printing the message but not stopping the job execution and also not recording it into log file also. Please help me out.
Thank & Regards
---------------------
Lokanath B.
6 REPLIES
Community Manager

Re: Handling with custom messages.

Hi
You can returns a status string such as "successful" from your routine function if the function works well, otherwise, returns the error message, and then trigger a tDie component to stop the job base on the return status, and use a tLogCatcher in the job to capture the die message defined on tDie. For example:
tJava--runIf_1--tDie
--runIf_2--tOracleConnection------>tOracleInput------>tMap---->tOracleOutput----tOracleCommit.
tLogCatcher--main--tFileOutputDelimited(log the error message to a file)
on tJava:
String statusOrErrorMessage=yourRoutineName.methodName();
if(status.equals("successful")){
globalMap.put("hasError",false);
}else
globalMap.put("hasError",true);
globalMap.put("errorMessage",status);
}
Set the condition of runIf_1 as:
(Boolean)globalMap.get("hasError")
Set the condition of runIf_2 as:
!(Boolean)globalMap.get("hasError")
on tDie, customize the die message as: (String)globalMap.get("errorMessage")
Hope this can give you a tip!

Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Handling with custom messages.

Hello Shong
Thank u very much for your reply. We can stop the flow of execution by using tDie component as u said, after exection of a job talend records all the stats and logs into files that we defined in project settings. and in the same way my custom messages should also be recorded in the files.
project settings---job settings--stats & logs-----here we are defining the stats & log file details.
plz suggest me with a proper solution.
Thanks & regards
--------------------
Lokanath B.
Community Manager

Re: Handling with custom messages.

Hi
If you have configured the stats&logs settings in the job settings, you don't need a tLogCatcher component in the job. Make sure the 'Catch user errors' box is checked on the Use logs (tLogCatcher) component, this option will capture the die message thrown by tDie component.
What's the problem you meet now? Are you able to return the error message from your routine and write it to the ?die message? field on tDie component?
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Handling with custom messages.

Thank U very much shong i got it ...
thanks & regards
--------------------
Lokanath B
One Star

Re: Handling with custom messages.

Hello Everybody,
i am facing some problems during handling exceptions with custom error messages as Shong suggested using tDie component and the errors i am facing is :
actually in my routine i am handling the exceptions like following :
p s v abc() throws Exception
{
try{
//my code goes...
}
catch(Exception e)
{
throw new Exception("the exception occurred in XXX routine and in abc() is :: "+e.getMessage());
}
}
i am not getting the message what i expect and it is passing the all null values to output and tOracleOutput is throwing the error like null values can't be inserted.
Community Manager

Re: Handling with custom messages.

Hi
Can you upload a screenshot of your job? How do you call the routine in tJavaRow component?
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business